Source Code
models.py file
from django.db import models
class Organism( models.Model ):
organism = models.SlugField( primary_key=True )
class Meta:
ordering = ["organism"]
class TheLoop( models.Model ):
loop = models.SlugField( primary_key=True )
target_organism = models.ForeignKey( Organism )
host_organism = models.ForeignKey( Organism )
class Meta:
ordering = ["target_organism","host_organism"] #"loop"
class InfinitLoop( models.Model):
infinity = models.SlugField( primary_key=True )
loop = models.ForeignKey( TheLoop )
class Meta:
ordering = ["loop"] #"infinity"
test.py file
from django.test import TestCase
from .models import InfinitLoop , TheLoop
class InfinitLoopTests( TestCase ):
def test_infinitloop( self ):
#print( TheLoop.objects.all() )
print( InfinitLoop.objects.all() )
Trace Back
(djangovenv) JOSHUA ~/src/django/tests $ PYTHONPATH=..:$PYTHONPATH python runtests.py infinitloop
Testing against Django installed in '/Users/buchere/src/django/django'
Creating test database for alias 'default'...
Creating test database for alias 'other'...
E
======================================================================
ERROR: test_infinitloop (infinitloop.test.InfinitLoopTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/buchere/src/django/tests/infinitloop/test.py", line 8, in test_infinitloop
print( InfinitLoop.objects.all() )
File "/Users/buchere/src/django/django/db/models/query.py", line 234, in __repr__
data = list(self[:REPR_OUTPUT_SIZE + 1])
File "/Users/buchere/src/django/django/db/models/query.py", line 258, in __iter__
self._fetch_all()
File "/Users/buchere/src/django/django/db/models/query.py", line 1061, in _fetch_all
self._result_cache = list(self.iterator())
File "/Users/buchere/src/django/django/db/models/query.py", line 52, in __iter__
results = compiler.execute_sql()
File "/Users/buchere/src/django/django/db/models/sql/compiler.py", line 824, in execute_sql
sql, params = self.as_sql()
File "/Users/buchere/src/django/django/db/models/sql/compiler.py", line 373, in as_sql
extra_select, order_by, group_by = self.pre_sql_setup()
File "/Users/buchere/src/django/django/db/models/sql/compiler.py", line 49, in pre_sql_setup
order_by = self.get_order_by()
File "/Users/buchere/src/django/django/db/models/sql/compiler.py", line 285, in get_order_by
field, self.query.get_meta(), default_order=asc))
File "/Users/buchere/src/django/django/db/models/sql/compiler.py", line 570, in find_ordering_name
order, already_seen))
File "/Users/buchere/src/django/django/db/models/sql/compiler.py", line 564, in find_ordering_name
raise FieldError('Infinite loop caused by ordering.')
django.core.exceptions.FieldError: Infinite loop caused by ordering.
----------------------------------------------------------------------
Ran 1 test in 0.002s
FAILED (errors=1)
Destroying test database for alias 'default'...
Destroying test database for alias 'other'...
(djangovenv) JOSHUA ~/src/django/tests $
The models didn't appear obviously invalid to me (but if they are, maybe we could add a system check about it). I could reproduce the traceback with the code above.