From cf12257db23fa248c89a3da3f718aa01a50ca659 Mon Sep 17 00:00:00 2001 From: Sergey Fedoseev Date: Sat, 2 Dec 2017 07:48:49 +0500 Subject: Fixed #28863 -- Fixed filter on annotation that contains Q. --- django/db/models/sql/where.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'django/db/models/sql') diff --git a/django/db/models/sql/where.py b/django/db/models/sql/where.py index 0ca95f7018..1635a686c2 100644 --- a/django/db/models/sql/where.py +++ b/django/db/models/sql/where.py @@ -26,6 +26,7 @@ class WhereNode(tree.Node): contains_aggregate attribute. """ default = AND + resolved = False def split_having(self, negated=False): """ @@ -108,7 +109,7 @@ class WhereNode(tree.Node): # around the inner SQL in the negated case, even if the # inner SQL contains just a single expression. sql_string = 'NOT (%s)' % sql_string - elif len(result) > 1: + elif len(result) > 1 or self.resolved: sql_string = '(%s)' % sql_string return sql_string, result_params @@ -181,6 +182,11 @@ class WhereNode(tree.Node): def is_summary(self): return any(child.is_summary for child in self.children) + def resolve_expression(self, *args, **kwargs): + clone = self.clone() + clone.resolved = True + return clone + class NothingNode: """A node that matches nothing.""" -- cgit v1.3