summaryrefslogtreecommitdiff
path: root/django/db/models/sql
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2011-02-08 14:07:14 +0000
committerRussell Keith-Magee <russell@keith-magee.com>2011-02-08 14:07:14 +0000
commit5e485a15ad07b492e648fe784ddd136d36ffcac4 (patch)
tree198678082bf2b562e141d4d15644abbb83d4204e /django/db/models/sql
parentbbfdb36b5485adc84adf7c6090cbd0ea9789d02b (diff)
[1.2.X] Fixed #13815 -- Ensure that reverse exclude lookups on nullable foreign keys exclude null values. Thanks to bpeschier for the report and patch.
Backport of r15458 from trunk. git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@15460 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/db/models/sql')
-rw-r--r--django/db/models/sql/query.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py
index f08544d259..0a5e428897 100644
--- a/django/db/models/sql/query.py
+++ b/django/db/models/sql/query.py
@@ -1474,6 +1474,13 @@ class Query(object):
query.bump_prefix()
query.clear_ordering(True)
query.set_start(prefix)
+ # Adding extra check to make sure the selected field will not be null
+ # since we are adding a IN <subquery> clause. This prevents the
+ # database from tripping over IN (...,NULL,...) selects and returning
+ # nothing
+ alias, col = query.select[0]
+ query.where.add((Constraint(alias, col, None), 'isnull', False), AND)
+
self.add_filter(('%s__in' % prefix, query), negate=True, trim=True,
can_reuse=can_reuse)