Opened 16 years ago
Closed 16 years ago
#8223 closed (invalid)
Infinite loop caused by ordering
Reported by: | David Cramer | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
The model itself contains no data in the database:
class Syntax(models.Model): name = models.CharField(max_length=32) lexer = models.CharField(max_length=32) order = models.IntegerField(default=10) parent = models.ForeignKey('self', blank=True, null=True) children= models.SmallIntegerField(default=0) class Meta: ordering = ('parent', 'order', 'name') Traceback: File "/Library/Python/2.5/site-packages/django/core/handlers/base.py" in get_response 77. request.path_info) File "/Library/Python/2.5/site-packages/django/core/urlresolvers.py" in resolve 240. sub_match = pattern.resolve(new_path) File "/Library/Python/2.5/site-packages/django/core/urlresolvers.py" in resolve 240. sub_match = pattern.resolve(new_path) File "/Library/Python/2.5/site-packages/django/core/urlresolvers.py" in resolve 179. return self.callback, args, kwargs File "/Library/Python/2.5/site-packages/django/core/urlresolvers.py" in _get_callback 185. self._callback = get_callable(self._callback_str) File "/Users/dcramer/Development/django-compositepks/django/utils/functional.py" in wrapper 130. result = func(*args) File "/Library/Python/2.5/site-packages/django/core/urlresolvers.py" in get_callable 54. lookup_view = getattr(__import__(mod_name, {}, {}, ['']), func_name) File "/Users/dcramer/Development/pastethat/pastes/views.py" in <module> 6. from forms import PasteFileForm, PasteLinkForm, PasteTextForm File "/Users/dcramer/Development/pastethat/pastes/forms.py" in <module> 55. class PasteTextForm(forms.Form): File "/Users/dcramer/Development/pastethat/pastes/forms.py" in PasteTextForm 56. syntax = GroupedModelChoiceField(queryset=Syntax.objects.all(), empty_label='(Automatic)', required=False) File "/Library/Python/2.5/site-packages/django/forms/models.py" in __init__ 475. self.queryset = queryset File "/Library/Python/2.5/site-packages/django/forms/models.py" in _set_queryset 483. self.widget.choices = self.choices File "/Users/dcramer/Development/pastethat/pastes/forms.py" in _get_choices 41. loop(self.queryset) File "/Users/dcramer/Development/pastethat/pastes/forms.py" in loop 24. for parent, objects in itertools.groupby(sorted(objects, key=func), key=func): File "/Library/Python/2.5/site-packages/django/db/models/query.py" in __len__ 153. self._result_cache.extend(list(self._iter)) File "/Library/Python/2.5/site-packages/django/db/models/query.py" in iterator 266. for row in self.query.results_iter(): File "/Library/Python/2.5/site-packages/django/db/models/sql/query.py" in results_iter 200. for rows in self.execute_sql(MULTI): File "/Library/Python/2.5/site-packages/django/db/models/sql/query.py" in execute_sql 1603. sql, params = self.as_sql() File "/Library/Python/2.5/site-packages/django/db/models/sql/query.py" in as_sql 255. ordering = self.get_ordering() File "/Library/Python/2.5/site-packages/django/db/models/sql/query.py" in get_ordering 613. self.model._meta, default_order=asc): File "/Library/Python/2.5/site-packages/django/db/models/sql/query.py" in find_ordering_name 666. order, already_seen)) File "/Library/Python/2.5/site-packages/django/db/models/sql/query.py" in find_ordering_name 660. raise FieldError('Infinite loop caused by ordering.')
Note:
See TracTickets
for help on using tickets.
The error isn't related to data in the database. It's an error in the model definition (the ordering by parent, which uses the default model's ordering, which includes parent, etc). Replace
parent
withparent__id
in the ordering if you want the old (somewhat incorrect) behaviour.