#9425 closed (wontfix)
select_related does not descend ForeignKey fields which can be null
Reported by: | fas | Owned by: | fas |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.0 |
Severity: | Keywords: | select_related, null, foreignkey, ignored | |
Cc: | simon@… | Triage Stage: | Unreviewed |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
ForeignKey fields which have the "null" property set to true are ignored by select_related() even though fill_related_selections() is prepared to use a left join for such fields and would deliver correct results.
Attachments (2)
Change History (8)
by , 16 years ago
Attachment: | query_utils_patch.diff added |
---|
comment:1 by , 16 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
by , 16 years ago
Attachment: | select-related-on-null.patch added |
---|
comment:2 by , 16 years ago
Cc: | added |
---|---|
Resolution: | invalid |
Status: | closed → reopened |
comment:3 by , 16 years ago
Resolution: | → wontfix |
---|---|
Status: | reopened → closed |
If you want to descend nullable foreign keys, write them out in the select_related()
call. It's not really that onerous. We don't need multiple ways to do this, since selecting across nullable relations is something to be avoided as much as possible.
comment:4 by , 16 years ago
Resolution: | wontfix |
---|---|
Status: | closed → reopened |
It actually is a bit onerous to maintain the list of foreign keys, once you want _one_ nullable foreign key.
That's what follow_nulls is False by default, but exists. For instance, it makes sense to follow null relations when JSON encoding Django models.
comment:5 by , 16 years ago
Resolution: | → wontfix |
---|---|
Status: | reopened → closed |
Please don't reopen tickets closed wontfix by a core developer. The right way to get a wontfix decision reconsidered is to raise the issue on django-developers.
The above patch, select-related-on-null.patch, lets you choose if you want select_related to descend into fields marked as null=True.
Since you can use select_related('field-name') to specify a nullable field, but sometimes you just know that you want all of them.