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 /tests/regressiontests | |
| 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 'tests/regressiontests')
| -rw-r--r-- | tests/regressiontests/queries/models.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/regressiontests/queries/models.py b/tests/regressiontests/queries/models.py index 67f2cc098d..22fa4f7803 100644 --- a/tests/regressiontests/queries/models.py +++ b/tests/regressiontests/queries/models.py @@ -97,6 +97,20 @@ class X(models.Model): class Y(models.Model): x1 = models.ForeignKey(X, related_name='y1') +# Some models with a cycle in the default ordering. This would be bad if we +# didn't catch the infinite loop. +class LoopX(models.Model): + y = models.ForeignKey('LoopY') + + class Meta: + ordering = ['y'] + +class LoopY(models.Model): + x = models.ForeignKey(LoopX) + + class Meta: + ordering = ['x'] + __test__ = {'API_TESTS':""" >>> t1 = Tag(name='t1') >>> t1.save() @@ -373,6 +387,13 @@ Bug #2076 >>> Cover.objects.all() [<Cover: first>, <Cover: second>] +# If you're not careful, it's possible to introduce infinite loops via default +# ordering on foreign keys in a cycle. We detect that. +>>> LoopX.objects.all() +Traceback (most recent call last): +... +TypeError: Infinite loop caused by ordering. + # If the remote model does not have a default ordering, we order by its 'id' # field. >>> Item.objects.order_by('creator', 'name') |
