#12420: "OneToOneField doesn't allow assignment of None"
------------------------------------------+---------------------------------
 Reporter:  kbrownlees                    |       Owner:  nobody    
   Status:  new                           |   Milestone:            
Component:  Database layer (models, ORM)  |     Version:  1.1       
 Keywords:                                |       Stage:  Unreviewed
Has_patch:  0                             |  
------------------------------------------+---------------------------------
 In
 http://code.djangoproject.com/browser/django/trunk/django/forms/models.py
 (R:11874)
 line 53 it states:
 {{{
 53              # OneToOneField doesn't allow assignment of None. Guard
 against that
 54              # instead of allowing it and throwing an error.
 55              if isinstance(f, models.OneToOneField) and cleaned_data
 [f.name] is None:
 56                  continue
 }}}
 Further reading of the function SingleRelatedObjectDescriptor which
 seems to implement most of the OTOF functionality actually states:

 
http://code.djangoproject.com/browser/django/trunk/django/db/models/fields/related.py
 (R:11878)

 {{{
 207             # If null=True, we can assign null here, but otherwise
 the value needs
 208             # to be an instance of the related class.
 209             if value is None and self.related.field.null == False:
 }}}
 It seems that when the code in models.py was written it was by someone who
 simply had null=False set, which meant that the OTOF (correctly) could not
 have a None value.

 I found the issue when trying to set a OTOF as null in an admin form it
 says "saved successfully" but never changes the value.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/12420>
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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.


Reply via email to