Fixed #10414 -- Make select_related fail on invalid field names.

This commit is contained in:
Niclas Olofsson 2014-12-04 21:47:48 +01:00
parent ce2eff7e48
commit 45d4e43d2d
4 changed files with 133 additions and 9 deletions

View file

@ -633,6 +633,24 @@ lookups::
...
ValueError: Cannot query "<Book: Django>": Must be "Author" instance.
``select_related()`` now checks given fields
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
``select_related()`` now validates that given fields actually exist. Previously,
nonexisting fields were silently ignored. Now, an error is raised::
>>> book = Book.objects.select_related('nonexisting_field')
Traceback (most recent call last):
...
ValueError: Invalid field name(s) given in select_related: 'nonexisting_field'
The validation also makes sure that the given field is relational::
>>> book = Book.objects.select_related('name')
Traceback (most recent call last):
...
ValueError: Non-relational field given in select_related: 'name'
Default ``EmailField.max_length`` increased to 254
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~