#12708: Django raises DoesNotExist when consulting an empty ForeignKey field
---------------------------------------------------+------------------------
          Reporter:  lsaffre                       |         Owner:  nobody     
            
            Status:  closed                        |     Milestone:             
            
         Component:  Database layer (models, ORM)  |       Version:  SVN        
            
        Resolution:  invalid                       |      Keywords:  ForeignKey 
DoesNotExist
             Stage:  Unreviewed                    |     Has_patch:  0          
            
        Needs_docs:  0                             |   Needs_tests:  0          
            
Needs_better_patch:  0                             |  
---------------------------------------------------+------------------------
Changes (by lukeplant):

  * status:  new => closed
  * needs_better_patch:  => 0
  * resolution:  => invalid
  * needs_tests:  => 0
  * needs_docs:  => 0

Comment:

 I think the behaviour is consistent.  If the `journal_id` attribute was
 set to an id which did not exist in the database, then you would get the
 same !DoesNotExist behaviour.  It is also symmetric with the behaviour of
 trying to set `o.journal`, which results in an exception.

 To put simply, `None` is never the value of non-nullable foreign key
 object - you cannot set or get `None` as the value.  If you want the
 foreign key value, rather than the object, use `journal_id`, not
 `journal`.

 I've persuaded myself that this behaviour is intended and good, and
 changing it could be a significant backwards incompatibility anyway, so
 I'm closing INVALID.

 Cheers.

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