diff options
Diffstat (limited to 'django/db/models/sql')
| -rw-r--r-- | django/db/models/sql/query.py | 6 | ||||
| -rw-r--r-- | django/db/models/sql/where.py | 6 |
2 files changed, 10 insertions, 2 deletions
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index 959990f628..6836337429 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -1077,7 +1077,11 @@ class Query(object): # it's short-circuited in the Where class. # We also need to handle the case where a subquery is provided entry = self.where_class() - entry.add((Constraint(alias, col, None), 'isnull', True), AND) + entry.add(( + Constraint(alias, col, None, eliminatable_if=lambda connection: not getattr(connection.features, "sql_nulls", True)), + 'isnull', + True + ), AND) entry.negate() self.where.add(entry, AND) diff --git a/django/db/models/sql/where.py b/django/db/models/sql/where.py index 4e5a647259..e953bca703 100644 --- a/django/db/models/sql/where.py +++ b/django/db/models/sql/where.py @@ -267,8 +267,9 @@ class Constraint(object): An object that can be passed to WhereNode.add() and knows how to pre-process itself prior to including in the WhereNode. """ - def __init__(self, alias, col, field): + def __init__(self, alias, col, field, eliminatable_if=None): self.alias, self.col, self.field = alias, col, field + self.elimintable_if = eliminatable_if def __getstate__(self): """Save the state of the Constraint for pickling. @@ -321,6 +322,9 @@ class Constraint(object): except ObjectDoesNotExist: raise EmptyShortCircuit + if self.elimintable_if and self.elimintable_if(connection): + raise FullResultSet + return (self.alias, self.col, db_type), params def relabel_aliases(self, change_map): |
