Opened 16 years ago
Closed 16 years ago
#7716 closed (fixed)
select_related() with nullable ForeignKeys screws up when rows actually have a null value
Reported by: | miracle2k | Owned by: | Malcolm Tredinnick |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
class Review(models.Model): author = models.ForeignKey(Person, blank=True, null=True)
>>> Review.objects.filter(author__isnull=True)[0].author None >>> Review.objects.select_related('author').filter(author__isnull=True)[0].author <type 'exceptions.TypeError'>: coercing to Unicode: need string or buffer, NoneType found >>> r = Review.objects.select_related('author').filter(author__isnull=True)[0] >>> type(r.author) <class 'proj.app.models.person.Person'>
Attachments (1)
Change History (4)
by , 16 years ago
Attachment: | 7716-select-related.diff added |
---|
comment:1 by , 16 years ago
comment:2 by , 16 years ago
Owner: | changed from | to
---|---|
Triage Stage: | Unreviewed → Accepted |
Yes, that is very unlikely to the way to fix this. It's at the wrong level. I'm looking at this. I suspect it might be related to #7530 and a couple of other semi-reports I've seen. I'm not going to apply any workaround; will fix it properly.
comment:3 by , 16 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
See attached file; this is probably not the best way to fix this, but it makes the problem go away ;)