From 06de130dae8b7a6c95143077d7a82fab37da0bc0 Mon Sep 17 00:00:00 2001 From: Anssi Kääriäinen Date: Thu, 28 Feb 2013 15:04:12 +0200 Subject: Fixed #12823 -- Was already fixed in master, tests added Also added a little improvement to sql/query.py to get rid of non-necessary IS NOT NULL check. --- django/db/models/sql/query.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'django/db/models/sql') diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index 64a3e7075b..9af7544db3 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -1204,7 +1204,8 @@ class Query(object): if negate: self.promote_joins(join_list) - if lookup_type != 'isnull' and (self.is_nullable(target) or len(join_list) > 1): + if (lookup_type != 'isnull' and ( + self.is_nullable(target) or self.alias_map[join_list[-1]].join_type == self.LOUTER)): # The condition added here will be SQL like this: # NOT (col IS NOT NULL), where the first NOT is added in # upper layers of code. The reason for addition is that if col @@ -1447,7 +1448,7 @@ class Query(object): # nothing if self.is_nullable(query.select[0].field): alias, col = query.select[0].col - query.where.add((Constraint(alias, col, None), 'isnull', False), AND) + query.where.add((Constraint(alias, col, query.select[0].field), 'isnull', False), AND) # Still make sure that the trimmed parts in the inner query and # trimmed prefix are in sync. So, use the trimmed_joins to make sure -- cgit v1.3