#12708: Django raises DoesNotExist when consulting an empty ForeignKey field
-------------------------------------+-------------------------------------
     Reporter:  lsaffre              |                    Owner:  nobody
         Type:  Uncategorized        |                   Status:  closed
    Component:  Database layer       |                  Version:  master
  (models, ORM)                      |               Resolution:  invalid
     Severity:  Normal               |             Triage Stage:
     Keywords:  ForeignKey           |  Unreviewed
  DoesNotExist                       |      Needs documentation:  0
    Has patch:  0                    |  Patch needs improvement:  0
  Needs tests:  0                    |                    UI/UX:  0
Easy pickings:  0                    |
-------------------------------------+-------------------------------------
Changes (by Luis):

 * ui_ux:   => 0
 * type:   => Uncategorized
 * severity:   => Normal
 * easy:   => 0


Comment:

 It shouldn't be considered invalid, even worse to be considered as a
 "consistent behavior". Reason: this only happens with related fields, and
 not with normal fields.

 If I have:

 class B(Model):
     name = CharField(max_length=30) #example

 class A(Model):
     #neither of these fields allow null
     count = PositiveSmallIntegerField()
     ref_a = ForeignKey(B)

 And issue:

     a = A()
     ...
     a.count #will return
     a.ref_a #will raise exception

 That does not let me traverse model properties without asking for
 forgiveness everytime. Why throwing DoesNotExist error and not throwing a
 ValueError or AttributeError for count property? Either trigger an error
 (ValueError, AttributeError, whatever) in non-related properties OR (xor)
 stop throwing errors when a FK has a null value (and does not accept it).

-- 
Ticket URL: <https://code.djangoproject.com/ticket/12708#comment:2>
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/065.e20ff3cdcd47c947ea472ef4d57202fc%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to