mirror of https://github.com/django/django.git
Refs #25367 -- Made Query.build_filter() raise TypeError on non-conditional expressions.
This commit is contained in:
parent
e9a0e1d4f6
commit
f97a6123c0
|
@ -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
|
||||
)
|
||||
|
|
|
@ -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()))
|
||||
|
|
Loading…
Reference in New Issue