#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        
       
        Resolution:                                |      Keywords:  
OneToOneField, bug
             Stage:  Accepted                      |     Has_patch:  0          
       
        Needs_docs:  0                             |   Needs_tests:  0          
       
Needs_better_patch:  0                             |  
---------------------------------------------------+------------------------
Comment (by gsakkis):

 At the very least, I expect a well-thought out exception message that
 explains what happened and why, like those checked for a few lines above:

 {{{
 if value is None and self.related.field.null == False:
     raise ValueError('Cannot assign None: "%s.%s" does not allow null
 values.' %
                                         (instance._meta.object_name,
 self.related.get_accessor_name()))
 elif value is not None and not isinstance(value, self.related.model):
     raise ValueError('Cannot assign "%r": "%s.%s" must be a "%s"
 instance.' %
           (value, instance._meta.object_name,
            self.related.get_accessor_name(),
 self.related.opts.object_name))
 }}}

 The fact that there is no such message for this case means that it was
 missed, it's not a deliberate choice.

 As for what it should happen, I think it should do the equivalent of what
 the ForeignRelatedObjectsDescriptor does for foreign keys: make
 `A.link_to_B = None`, `B.link_to_A = None` and `B.save()`, thus breaking
 the relation between A and B (we're always talking about a `null=True`
 OneToOneField).

-- 
Ticket URL: <http://code.djangoproject.com/ticket/14368#comment:4>
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.

Reply via email to