summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2008-03-11 08:23:51 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2008-03-11 08:23:51 +0000
commitf3ed30f377051c3fef3d184241ed5271fbe61854 (patch)
tree9002ad05abfcd6add32b54318a750674bfd9a588
parent3176bebffd7a7e3ba131da2d1b3f9776e159f0a8 (diff)
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
-rw-r--r--django/db/models/sql/query.py6
-rw-r--r--tests/regressiontests/queries/models.py5
2 files changed, 8 insertions, 3 deletions
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py
index 7d24701438..491e5b2f5b 100644
--- a/django/db/models/sql/query.py
+++ b/django/db/models/sql/query.py
@@ -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:
diff --git a/tests/regressiontests/queries/models.py b/tests/regressiontests/queries/models.py
index 17476217cd..7185558f45 100644
--- a/tests/regressiontests/queries/models.py
+++ b/tests/regressiontests/queries/models.py
@@ -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')