summaryrefslogtreecommitdiff
path: root/django/db/models/query_utils.py
diff options
context:
space:
mode:
authorAnssi Kääriäinen <akaariai@gmail.com>2015-05-11 10:02:41 +0300
committerTim Graham <timograham@gmail.com>2015-05-11 11:17:37 -0400
commit056a91dbfae9e741cd4bf033d3062d3d35ff4d90 (patch)
treecaacd938b7f22b75e57c90e67ae007c0b4ceedc2 /django/db/models/query_utils.py
parentd3a8f36fdb3094e58db24065bc77ec790b95c789 (diff)
[1.8.x] Fixed #24766 -- Added join promotion for Case expressions
Backport of be9d645346a20a6c394bf70d47b1b1d5c81ff530 from master
Diffstat (limited to 'django/db/models/query_utils.py')
-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