#34586: create does not save reverse OneToOne relantionship and does not raise 
an
Exception
-------------------------------------+-------------------------------------
               Reporter:  alarivas   |          Owner:  nobody
                   Type:  Bug        |         Status:  new
              Component:  Database   |        Version:  4.2
  layer (models, ORM)                |
               Severity:  Normal     |       Keywords:
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 When creating an object with a reverse OneToOne relationship as an
 argument, the method Model.create does not set the relation but does not
 raise an Error either.

 Example:

 models:

 {{{
 from django.db import models

 class Place(models.Model):
     pass


 class Restaurant(models.Model):
     place = models.OneToOneField(
         Place,
         on_delete=models.CASCADE,
         null=True,
     )
 }}}

 With these models if you try this:

 {{{
 place = Place.objects.create()
 restaurant = Restaurant.objects.create()

 place.restaurant = restaurant
 place.save(update_fields=["restaurant"])
 }}}


 You will get this error:

 {{{
 ValueError: The following fields do not exist in this model, are m2m
 fields, or are non-concrete fields: restaurant
 }}}


 But if you try with this code:

 {{{
 restaurant = Restaurant.objects.create()
 place = Place.objects.create(restaurant=restaurant)
 }}}

 You will not get an Exception and restaurant will not be related with
 place either. I do understand you can't save in a reverse OneToOne
 relation but I think this behavior is inconsistent because of the missing
 Exception.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34586>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/01070188417d671c-a800c608-edb3-421c-b2b1-9d434afb4b82-000000%40eu-central-1.amazonses.com.

Reply via email to