From 056a91dbfae9e741cd4bf033d3062d3d35ff4d90 Mon Sep 17 00:00:00 2001 From: Anssi Kääriäinen Date: Mon, 11 May 2015 10:02:41 +0300 Subject: [1.8.x] Fixed #24766 -- Added join promotion for Case expressions Backport of be9d645346a20a6c394bf70d47b1b1d5c81ff530 from master --- django/db/models/query_utils.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'django') 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 -- cgit v1.3