Opened 10 years ago

Closed 9 years ago

#24687 closed Bug (fixed)

select_related field validation doesn't work for nested non-relation fields

Reported by: Tim Graham Owned by: Tim Graham
Component: Database layer (models, ORM) Version: 1.8
Severity: Normal Keywords:
Cc: github@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The validation added in #10414 only occurs if the field is on the immediate model, or if it's invalid:

>>> Person.objects.select_related('foo')
django.core.exceptions.FieldError: Invalid field name(s) given in select_related: 'foo'. Choices are: hometown
>>> Person.objects.select_related('hometown__foo')
django.core.exceptions.FieldError: Invalid field name(s) given in select_related: 'foo'. Choices are: mayor
>>> Person.objects.select_related('hometown__name')
# query = select ... blah
[ Person object ...]
>>> Person.objects.select_related('name')
django.core.exceptions.FieldError: Non-relational field given in select_related: 'name'. Choices are: hometown

Notice how it will happily accept the third one. Failing test attached.

Attachments (1)

24687-test.diff (816 bytes ) - added by Tim Graham 10 years ago.

Download all attachments as: .zip

Change History (7)

by Tim Graham, 10 years ago

Attachment: 24687-test.diff added

comment:1 by no, 10 years ago

Cc: github@… added

comment:2 by Tim Graham, 9 years ago

Has patch: set
Owner: changed from nobody to Tim Graham
Status: newassigned

comment:3 by Tim Graham, 9 years ago

Patch needs improvement: set

A GIS failure needs to be addressed.

comment:4 by Tim Graham, 9 years ago

Patch needs improvement: unset

comment:5 by Claude Paroz, 9 years ago

Triage Stage: AcceptedReady for checkin

comment:6 by Tim Graham <timograham@…>, 9 years ago

Resolution: fixed
Status: assignedclosed

In 67732a9:

Fixed #24687 -- Added select_related() validation for nested non-relational fields.

The removed test was added in the original select_related() validation
patch (45d4e43d2d25b902e3821b612209afa951a8bcb8), but there doesn't
seem to be any reason for it.

Thanks Claude Paroz for help and review.

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