Django

Code

Changeset 7224

Show
Ignore:
Timestamp:
03/11/08 03:23:51 (7 months ago)
Author:
mtredinnick
Message:

queryset-refactor: Infinite loop detection in model ordering was being a little
too aggressive. Fixed that.

Files:

Legend:

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

    r7220 r7224  
    519519        # If we get to this point and the field is a relation to another model, 
    520520        # append the default ordering for that model. 
    521         if len(joins) > 1 and opts.ordering: 
     521        if field.rel and len(joins) > 1 and opts.ordering: 
    522522            # Firstly, avoid infinite loops. 
    523523            if not already_seen: 
    524                 already_seen = {} 
     524                already_seen = set() 
    525525            join_tuple = tuple([tuple(j) for j in joins]) 
    526526            if join_tuple in already_seen: 
    527527                raise FieldError('Infinite loop caused by ordering.') 
    528             already_seen[join_tuple] = True 
     528            already_seen.add(join_tuple) 
    529529 
    530530            results = [] 
  • django/branches/queryset-refactor/tests/regressiontests/queries/models.py

    r7220 r7224  
    408408FieldError: Infinite loop caused by ordering. 
    409409 
     410# ... but you can still order in a non-recursive fashion amongst linked fields 
     411# (the previous test failed because the default ordering was recursive). 
     412>>> LoopX.objects.all().order_by('y__x__id') 
     413[] 
     414 
    410415# If the remote model does not have a default ordering, we order by its 'id' 
    411416# field.