summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
Diffstat (limited to 'django')
-rw-r--r--django/db/models/query_utils.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/django/db/models/query_utils.py b/django/db/models/query_utils.py
index 10580f77a6..ac9405ec73 100644
--- a/django/db/models/query_utils.py
+++ b/django/db/models/query_utils.py
@@ -85,7 +85,12 @@ class Q(tree.Node):
return clone
def resolve_expression(self, query=None, allow_joins=True, reuse=None, summarize=False, for_save=False):
- clause, _ = query._add_q(self, reuse, allow_joins=allow_joins)
+ # We must promote any new joins to left outer joins so that when Q is
+ # used as an expression, rows aren't filtered due to joins.
+ joins_before = query.tables[:]
+ clause, joins = query._add_q(self, reuse, allow_joins=allow_joins)
+ joins_to_promote = [j for j in joins if j not in joins_before]
+ query.promote_joins(joins_to_promote)
return clause
@classmethod