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

Refs #25367 -- Made Query.build_filter() raise TypeError on non-conditional expressions.

This commit is contained in:
Simon Charette 2019-11-15 00:24:21 -05:00 committed by Mariusz Felisiak
parent e9a0e1d4f6
commit f97a6123c0
2 changed files with 9 additions and 1 deletions

View File

@ -1230,7 +1230,9 @@ class Query(BaseExpression):
allow_joins=allow_joins,
split_subq=split_subq,
)
if hasattr(filter_expr, 'resolve_expression') and getattr(filter_expr, 'conditional', False):
if hasattr(filter_expr, 'resolve_expression'):
if not getattr(filter_expr, 'conditional', False):
raise TypeError('Cannot filter against a non-conditional expression.')
condition = self.build_lookup(
['exact'], filter_expr.resolve_expression(self, allow_joins=allow_joins), True
)

View File

@ -144,3 +144,9 @@ class TestQuery(SimpleTestCase):
msg = 'Joined field references are not permitted in this query'
with self.assertRaisesMessage(FieldError, msg):
query.build_where(filter_expr)
def test_filter_non_conditional(self):
query = Query(Item)
msg = 'Cannot filter against a non-conditional expression.'
with self.assertRaisesMessage(TypeError, msg):
query.build_where(Func(output_field=CharField()))