summaryrefslogtreecommitdiff
path: root/django/db/models
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2009-01-08 05:16:21 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2009-01-08 05:16:21 +0000
commitd068ad0c01be9bb085c86a4e0c4dd047a85ce18d (patch)
treec17b333ef31e628019908a7d55196ab9bf50d042 /django/db/models
parentd00c013cc8477de9a75e4b4f5806034549e5a5e1 (diff)
Using querysets as an rvalue in filter() calls was causing an unnecessary
database query, due to a bool() call. This change stops that behaviour. git-svn-id: http://code.djangoproject.com/svn/django/trunk@9715 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/db/models')
-rw-r--r--django/db/models/query.py8
-rw-r--r--django/db/models/sql/where.py2
2 files changed, 10 insertions, 0 deletions
diff --git a/django/db/models/query.py b/django/db/models/query.py
index 2f9f9e24ec..563b902bb5 100644
--- a/django/db/models/query.py
+++ b/django/db/models/query.py
@@ -651,6 +651,10 @@ class QuerySet(object):
obj = self.values("pk")
return obj.query.as_nested_sql()
+ # When used as part of a nested query, a queryset will never be an "always
+ # empty" result.
+ value_annotation = True
+
class ValuesQuerySet(QuerySet):
def __init__(self, *args, **kwargs):
super(ValuesQuerySet, self).__init__(*args, **kwargs)
@@ -795,6 +799,10 @@ class EmptyQuerySet(QuerySet):
# (it raises StopIteration immediately).
yield iter([]).next()
+ # EmptyQuerySet is always an empty result in where-clauses (and similar
+ # situations).
+ value_annotation = False
+
def get_cached_row(klass, row, index_start, max_depth=0, cur_depth=0,
requested=None):
diff --git a/django/db/models/sql/where.py b/django/db/models/sql/where.py
index a9fca7df11..9ce1e7bf2d 100644
--- a/django/db/models/sql/where.py
+++ b/django/db/models/sql/where.py
@@ -66,6 +66,8 @@ class WhereNode(tree.Node):
# here in the future (using Python types is suggested for consistency).
if isinstance(value, datetime.datetime):
annotation = datetime.datetime
+ elif hasattr(value, 'value_annotation'):
+ annotation = value.value_annotation
else:
annotation = bool(value)