summaryrefslogtreecommitdiff
path: root/django/db/models/sql/query.py
diff options
context:
space:
mode:
authorAnssi Kääriäinen <akaariai@gmail.com>2012-08-21 18:43:08 +0300
committerAnssi Kääriäinen <akaariai@gmail.com>2012-08-21 21:23:57 +0300
commita193372753ad9d1d15ad5e2d6d06bbc07ca3f433 (patch)
tree2e0b3c6165a161c7b403c3e3bcb65fb538f31e59 /django/db/models/sql/query.py
parentfd58d6c258058f8ac54e241b21b949bdbe50059b (diff)
Fixed #17886 -- Fixed join promotion in ORed nullable queries
The ORM generated a query with INNER JOIN instead of LEFT OUTER JOIN in a somewhat complicated case. The main issue was that there was a chain of nullable FK -> non-nullble FK, and the join promotion logic didn't see the need to promote the non-nullable FK even if the previous nullable FK was already promoted to LOUTER JOIN. This resulted in a query like a LOUTER b INNER c, which incorrectly prunes results.
Diffstat (limited to 'django/db/models/sql/query.py')
-rw-r--r--django/db/models/sql/query.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py
index c62c9ac23e..27a4ac9ce5 100644
--- a/django/db/models/sql/query.py
+++ b/django/db/models/sql/query.py
@@ -910,7 +910,12 @@ class Query(object):
# Not all tables need to be joined to anything. No join type
# means the later columns are ignored.
join_type = None
- elif promote or outer_if_first:
+ elif (promote or outer_if_first
+ or self.alias_map[lhs].join_type == self.LOUTER):
+ # We need to use LOUTER join if asked by promote or outer_if_first,
+ # or if the LHS table is left-joined in the query. Adding inner join
+ # to an existing outer join effectively cancels the effect of the
+ # outer join.
join_type = self.LOUTER
else:
join_type = self.INNER