1
0
mirror of https://github.com/django/django.git synced 2024-12-22 17:16:24 +00:00

Fixed #29727 -- Made nonexistent joins in F() raise FieldError.

Regression in 2162f0983d.
This commit is contained in:
Alexander Holmbäck 2018-09-06 20:10:20 +00:00 committed by Tim Graham
parent aa16ec5474
commit f315d0423a
3 changed files with 10 additions and 2 deletions

View File

@ -1594,10 +1594,13 @@ class Query:
else:
field_list = name.split(LOOKUP_SEP)
join_info = self.setup_joins(field_list, self.get_meta(), self.get_initial_alias(), can_reuse=reuse)
targets, _, join_list = self.trim_joins(join_info.targets, join_info.joins, join_info.path)
targets, final_alias, join_list = self.trim_joins(join_info.targets, join_info.joins, join_info.path)
if len(targets) > 1:
raise FieldError("Referencing multicolumn fields with F() objects "
"isn't supported")
# Verify that the last lookup in name is a field or a transform:
# transform_function() raises FieldError if not.
join_info.transform_function(targets[0], final_alias)
if reuse is not None:
reuse.update(join_list)
col = _get_col(targets[0], join_info.targets[0], join_list[-1], simple_col)

View File

@ -9,4 +9,5 @@ Django 2.1.2 fixes several bugs in 2.1.1
Bugfixes
========
* ...
* Fixed a regression where nonexistent joins in ``F()`` no longer raised
``FieldError`` (:ticket:`29727`).

View File

@ -595,6 +595,10 @@ class BasicExpressionsTests(TestCase):
with self.assertRaisesMessage(FieldError, "Cannot resolve keyword 'nope' into field."):
list(Employee.objects.filter(firstname=F('nope')))
def test_incorrect_joined_field_in_F_expression(self):
with self.assertRaisesMessage(FieldError, "Cannot resolve keyword 'nope' into field."):
list(Company.objects.filter(ceo__pk=F('point_of_contact__nope')))
class IterableLookupInnerExpressionsTests(TestCase):
@classmethod