diff options
| author | Ian Foote <python@ian.feete.org> | 2021-04-02 18:25:20 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2021-07-09 11:43:06 +0200 |
| commit | f42ccdd835e5b3f0914b5e6f87621c648136ea36 (patch) | |
| tree | 49f0a1ecbd05b4d8d0049cec21ad564a663b427f /django/db/models/sql/query.py | |
| parent | f5dccbafb957841d0867f0b153d7f7123f0ec83d (diff) | |
Fixed #27021 -- Allowed lookup expressions in annotations, aggregations, and QuerySet.filter().
Thanks Hannes Ljungberg and Simon Charette for reviews.
Co-authored-by: Mariusz Felisiak <felisiak.mariusz@gmail.com>
Diffstat (limited to 'django/db/models/sql/query.py')
| -rw-r--r-- | django/db/models/sql/query.py | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index 87be8ea9f0..2412e6ad4e 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -1262,9 +1262,9 @@ class Query(BaseExpression): 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 - ) + condition = filter_expr.resolve_expression(self, allow_joins=allow_joins) + if not isinstance(condition, Lookup): + condition = self.build_lookup(['exact'], condition, True) clause = self.where_class() clause.add(condition, AND) return clause, [] |
