summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2007-11-29 22:07:58 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2007-11-29 22:07:58 +0000
commitbef4ca2bacfefd22fdf35b9c86d3ab714c67330f (patch)
treee556c7acd4a09ae4129b4999faed3ed00f9ac44b
parentdfe05d94b853073e2762250e1b4cd64ce9ef1df0 (diff)
queryset-refactor: Fixed an off-by-one error when filling the select-related
case. Only affects people using select_related() with the "depth" parameter *and* extra(select=...) simultaneously. Refs #6018. Thanks, Matthias Urlichs. git-svn-id: http://code.djangoproject.com/svn/django/branches/queryset-refactor@6755 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/db/models/sql/query.py7
-rw-r--r--tests/modeltests/select_related/models.py4
2 files changed, 9 insertions, 2 deletions
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py
index 9f303fa015..c1013ce99f 100644
--- a/django/db/models/sql/query.py
+++ b/django/db/models/sql/query.py
@@ -634,10 +634,13 @@ class Query(object):
self.rev_join_map[alias] = t_ident
return alias
- def fill_related_selections(self, opts=None, root_alias=None, cur_depth=0,
+ def fill_related_selections(self, opts=None, root_alias=None, cur_depth=1,
used=None):
"""
- Fill in the information needed for a select_related query.
+ Fill in the information needed for a select_related query. The current
+ "depth" is measured as the number of connections away from the root
+ model (cur_depth == 1 means we are looking at models with direct
+ connections to the root model).
"""
if self.max_depth and cur_depth > self.max_depth:
# We've recursed too deeply; bail out.
diff --git a/tests/modeltests/select_related/models.py b/tests/modeltests/select_related/models.py
index 78ba0ba764..a52cc986a4 100644
--- a/tests/modeltests/select_related/models.py
+++ b/tests/modeltests/select_related/models.py
@@ -147,6 +147,10 @@ __test__ = {'API_TESTS':"""
>>> len(db.connection.queries)
5
+>>> s = Species.objects.all().select_related(depth=1).extra(select={'a': 'select_related_species.id + 10'})[0]
+>>> s.id + 10 == s.a
+True
+
# Reset DEBUG to where we found it.
>>> settings.DEBUG = False
"""}