#14368: Reverse relation attribute for OneToOneField fails when set to None ------------------------------------------+--------------------------------- Reporter: gsakkis | Owner: nobody Status: new | Milestone: 1.3 Component: Database layer (models, ORM) | Version: 1.2 Keywords: OneToOneField, bug | Stage: Unreviewed Has_patch: 0 | ------------------------------------------+--------------------------------- Initially reported by reopening #12420 (http://code.djangoproject.com/ticket/12420#comment:10), moved to a new ticket after the assignee's suggestion.
Test case with the sample models used at #14043: {{{ In [6]: bob = Person.objects.create(age=34) In [7]: bobs_soul = Soul.objects.create(person=bob) In [8]: bob.soul == bobs_soul Out[8]: True In [9]: bob.soul = None --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) --> 258 setattr(value, self.related.field.attname, getattr(instance, self.related.field.rel.get_related_field().attname)) 259 260 # Since we already know what the related object is, seed the related AttributeError: 'NoneType' object has no attribute 'person_id' }}} The offending lines are http://code.djangoproject.com/browser/django/trunk/django/db/models/fields/related.py#L258 and http://code.djangoproject.com/browser/django/trunk/django/db/models/fields/related.py#L264. It's clearly a bug because the comment at http://code.djangoproject.com/browser/django/trunk/django/db/models/fields/related.py#L238 explicitly mentions "If null=True, we can assign null here". -- Ticket URL: <http://code.djangoproject.com/ticket/14368> Django <http://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 post to this group, send email to django-upda...@googlegroups.com. To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-updates?hl=en.