Opened 17 years ago

Closed 17 years ago

#4728 closed (invalid)

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

Reported by: bo@… Owned by: Adrian Holovaty
Component: Core (Other) Version: dev
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: no UI/UX: no

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 by bo <bo@…>, 17 years ago

Resolution: invalid
Status: newclosed

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