select_related field validation doesn't work for nested non-relation fields
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.
Change History
(7)
Has patch: |
set
|
Owner: |
changed from nobody to Tim Graham
|
Status: |
new → assigned
|
Patch needs improvement: |
set
|
Patch needs improvement: |
unset
|
Triage Stage: |
Accepted → Ready for checkin
|
Resolution: |
→ fixed
|
Status: |
assigned → closed
|
PR