mirror of
https://github.com/django/django.git
synced 2025-07-06 18:59:13 +00:00
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
This commit is contained in:
parent
dfe05d94b8
commit
bef4ca2bac
@ -634,10 +634,13 @@ class Query(object):
|
|||||||
self.rev_join_map[alias] = t_ident
|
self.rev_join_map[alias] = t_ident
|
||||||
return alias
|
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):
|
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:
|
if self.max_depth and cur_depth > self.max_depth:
|
||||||
# We've recursed too deeply; bail out.
|
# We've recursed too deeply; bail out.
|
||||||
|
@ -147,6 +147,10 @@ __test__ = {'API_TESTS':"""
|
|||||||
>>> len(db.connection.queries)
|
>>> len(db.connection.queries)
|
||||||
5
|
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.
|
# Reset DEBUG to where we found it.
|
||||||
>>> settings.DEBUG = False
|
>>> settings.DEBUG = False
|
||||||
"""}
|
"""}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user