Opened 8 years ago

Closed 8 years ago

#4728 closed (invalid)

ForeignKey that is blank and null should not return DoesNotExist err if null

Reported by: bo@… Owned by: adrian
Component: Core (Other) Version: master
Severity: Keywords: ForeignKey blank null DoesNotExist
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

#Best by example 

#A simple self refed model
class Message(models.Model):
   blurb = models.TextField()
   replied_message = models.ForeignKey('self', blank = True, null = True, default = None)

#Grab a row
r = Messages.objects.get(pk = 1)
#now if i ask the question
if not r.replied_message:
   #do something
else:
  #do something else




this will toss a DoesNotExist exception even-though it is perfectly acceptable to have this field be None
granted a try: except: would solve it, but that seems strange given the rules of blank and null
if this is a feature please ignore my post

Change History (1)

comment:1 Changed 8 years ago by bo <bo@…>

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

O piddle

IGNORE THIS

stupid DB error (the columns were set to 0 not NULL, if properly set to NULL, this works fine)

Note: See TracTickets for help on using tickets.
Back to Top