diff options
| author | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2008-01-28 16:08:34 +0000 |
|---|---|---|
| committer | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2008-01-28 16:08:34 +0000 |
| commit | a214c6b86a029d2f9aa873fbc93e4e2542be978d (patch) | |
| tree | aaf846a1f3206b07e0335b3f2277c9e2d3350ef5 /django | |
| parent | 3c490660c5a61cdf3a71e690d4bfc1a7dfa51955 (diff) | |
queryset-refactor: Added some error checking for a potential crasher if model ordering is set up in a cycle somehow. The error reporting here isn't perfect (it doesn't give any hints about what the infinite loop might be), but it's better than nothing.
git-svn-id: http://code.djangoproject.com/svn/django/branches/queryset-refactor@7046 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
| -rw-r--r-- | django/db/models/sql/query.py | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index cb8bbc36bf..af6ec2bfbc 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -507,7 +507,8 @@ class Query(object): result.append('%s %s' % (elt, order)) return result - def find_ordering_name(self, name, opts, alias=None, default_order='ASC'): + def find_ordering_name(self, name, opts, alias=None, default_order='ASC', + already_seen=None): """ Returns the table alias (the name might be ambiguous, the alias will not be) and column name for ordering by the given 'name' parameter. @@ -525,10 +526,18 @@ 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: + # Firstly, avoid infinite loops. + if not already_seen: + already_seen = {} + join_tuple = tuple([tuple(j) for j in joins]) + if join_tuple in already_seen: + raise TypeError('Infinite loop caused by ordering.') + already_seen[join_tuple] = True + results = [] for item in opts.ordering: results.extend(self.find_ordering_name(item, opts, alias, - order)) + order, already_seen)) return results if alias: |
