mirror of
https://github.com/django/django.git
synced 2025-07-05 18:29:11 +00:00
queryset-refactor: Infinite loop detection in model ordering was being a little
too aggressive. Fixed that. git-svn-id: http://code.djangoproject.com/svn/django/branches/queryset-refactor@7224 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
3176bebffd
commit
f3ed30f377
@ -518,14 +518,14 @@ class Query(object):
|
||||
|
||||
# If we get to this point and the field is a relation to another model,
|
||||
# append the default ordering for that model.
|
||||
if len(joins) > 1 and opts.ordering:
|
||||
if field.rel and len(joins) > 1 and opts.ordering:
|
||||
# Firstly, avoid infinite loops.
|
||||
if not already_seen:
|
||||
already_seen = {}
|
||||
already_seen = set()
|
||||
join_tuple = tuple([tuple(j) for j in joins])
|
||||
if join_tuple in already_seen:
|
||||
raise FieldError('Infinite loop caused by ordering.')
|
||||
already_seen[join_tuple] = True
|
||||
already_seen.add(join_tuple)
|
||||
|
||||
results = []
|
||||
for item in opts.ordering:
|
||||
|
@ -407,6 +407,11 @@ Traceback (most recent call last):
|
||||
...
|
||||
FieldError: Infinite loop caused by ordering.
|
||||
|
||||
# ... but you can still order in a non-recursive fashion amongst linked fields
|
||||
# (the previous test failed because the default ordering was recursive).
|
||||
>>> LoopX.objects.all().order_by('y__x__id')
|
||||
[]
|
||||
|
||||
# If the remote model does not have a default ordering, we order by its 'id'
|
||||
# field.
|
||||
>>> Item.objects.order_by('creator', 'name')
|
||||
|
Loading…
x
Reference in New Issue
Block a user