Opened 18 years ago
Closed 18 years ago
#4728 closed (invalid)
ForeignKey that is blank and null should not return DoesNotExist err if null
| Reported by: | 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
Note:
See TracTickets
for help on using tickets.
O piddle
IGNORE THIS
stupid DB error (the columns were set to 0 not NULL, if properly set to NULL, this works fine)