Opened 15 years ago

Closed 15 years ago

Last modified 15 years ago

#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)

query_utils_patch.diff (404 bytes ) - added by fas 15 years ago.
select-related-on-null.patch (4.5 KB ) - added by Simon Law 15 years ago.

Download all attachments as: .zip

Change History (8)

by fas, 15 years ago

Attachment: query_utils_patch.diff added

comment:1 by fas, 15 years ago

Resolution: invalid
Status: newclosed

by Simon Law, 15 years ago

comment:2 by Simon Law, 15 years ago

Cc: simon@… added
Resolution: invalid
Status: closedreopened

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.

comment:3 by Malcolm Tredinnick, 15 years ago

Resolution: wontfix
Status: reopenedclosed

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 Simon Law, 15 years ago

Resolution: wontfix
Status: closedreopened

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 Karen Tracey, 15 years ago

Resolution: wontfix
Status: reopenedclosed

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.

comment:6 by (none), 15 years ago

milestone: post-1.0

Milestone post-1.0 deleted

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