Django

Code

Changeset 7429

Show
Ignore:
Timestamp:
04/15/08 23:32:56 (3 months ago)
Author:
mtredinnick
Message:

queryset-refactor: Detect infinite ordering loops when relations refer to 'self'.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/queryset-refactor/django/db/models/sql/query.py

    r7426 r7429  
    536536            if not already_seen: 
    537537                already_seen = set() 
    538             join_tuple = tuple(joins
     538            join_tuple = tuple([self.alias_map[j][TABLE_NAME] for j in joins]
    539539            if join_tuple in already_seen: 
    540540                raise FieldError('Infinite loop caused by ordering.') 
  • django/branches/queryset-refactor/tests/regressiontests/queries/models.py

    r7418 r7429  
    111111    class Meta: 
    112112        ordering = ['x'] 
     113 
     114class LoopZ(models.Model): 
     115    z = models.ForeignKey('self') 
     116 
     117    class Meta: 
     118        ordering = ['z'] 
    113119 
    114120__test__ = {'API_TESTS':""" 
     
    427433FieldError: Infinite loop caused by ordering. 
    428434 
     435>>> LoopZ.objects.all() 
     436Traceback (most recent call last): 
     437... 
     438FieldError: Infinite loop caused by ordering. 
     439 
    429440# ... but you can still order in a non-recursive fashion amongst linked fields 
    430441# (the previous test failed because the default ordering was recursive). 
    431 >>> LoopX.objects.all().order_by('y__x__id') 
     442>>> LoopX.objects.all().order_by('y__x__y__x__id') 
    432443[] 
    433444