mirror of
https://github.com/django/django.git
synced 2025-08-03 10:34:04 +00:00
Fixed #10414 -- Made select_related() fail on invalid field names.
This commit is contained in:
parent
b27db97b23
commit
3daa9d60be
6 changed files with 180 additions and 11 deletions
|
@ -681,6 +681,24 @@ lookups::
|
|||
...
|
||||
ValueError: Cannot query "<Book: Django>": Must be "Author" instance.
|
||||
|
||||
``select_related()`` now checks given fields
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
``select_related()`` now validates that the given fields actually exist.
|
||||
Previously, nonexistent fields were silently ignored. Now, an error is raised::
|
||||
|
||||
>>> book = Book.objects.select_related('nonexistent_field')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
FieldError: Invalid field name(s) given in select_related: 'nonexistent_field'
|
||||
|
||||
The validation also makes sure that the given field is relational::
|
||||
|
||||
>>> book = Book.objects.select_related('name')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
FieldError: Non-relational field given in select_related: 'name'
|
||||
|
||||
Default ``EmailField.max_length`` increased to 254
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue