Permalink
Browse files

queryset-refactor: Infinite loop detection in model ordering was bein…

…g a little

too aggressive. Fixed that.


git-svn-id: http://code.djangoproject.com/svn/django/branches/queryset-refactor@7224 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
malcolmt committed Mar 11, 2008
1 parent 3176beb commit f3ed30f377051c3fef3d184241ed5271fbe61854
Showing with 8 additions and 3 deletions.
  1. +3 −3 django/db/models/sql/query.py
  2. +5 −0 tests/regressiontests/queries/models.py
@@ -518,14 +518,14 @@ def find_ordering_name(self, name, opts, alias=None, default_order='ASC',
# 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 @@ class Meta:
...
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')

0 comments on commit f3ed30f

Please sign in to comment.