diff options
| author | Russell Keith-Magee <russell@keith-magee.com> | 2011-02-08 14:06:02 +0000 |
|---|---|---|
| committer | Russell Keith-Magee <russell@keith-magee.com> | 2011-02-08 14:06:02 +0000 |
| commit | d3b38d578f41240442cb043012b0035a20eebd67 (patch) | |
| tree | b154f9c9c19135f3bf10fc9ba1e091de35f55d9d /django/db/models/sql | |
| parent | 340eaded4e30cf25bcd4e9781d33a617fe9c0f84 (diff) | |
Fixed #13815 -- Ensure that reverse exclude lookups on nullable foreign keys exclude null values. Thanks to bpeschier for the report and patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@15458 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/db/models/sql')
| -rw-r--r-- | django/db/models/sql/query.py | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index 43cb9d71b5..341765c608 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -1475,6 +1475,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) |
