Django

Code

Changeset 8898

Show
Ignore:
Timestamp:
09/02/08 22:48:25 (3 months ago)
Author:
mtredinnick
Message:

Fixed #8819 -- Don't include two copies of extra-select columns in the query.
This was triggered by r8794, but was, in fact, fairly fragile before then. The
current fix is the correct way we should be doing this.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/db/models/sql/query.py

    r8853 r8898  
    631631                col, order = get_order_dir(field, asc) 
    632632                elt = qn2(col) 
    633                 if distinct and elt not in select_aliases: 
     633                if distinct and col not in select_aliases: 
    634634                    ordering_aliases.append(elt) 
    635635                result.append('%s %s' % (elt, order)) 
  • django/trunk/tests/regressiontests/extra_regress/models.py

    r8673 r8898  
    9999[] 
    100100 
     101# Regression test for #8819: Fields in the extra(select=...) list should be 
     102# available to extra(order_by=...). 
     103>>> User.objects.extra(select={'extra_field': 1}).distinct() 
     104[<User: fred>] 
     105>>> User.objects.extra(select={'extra_field': 1}, order_by=['extra_field']) 
     106[<User: fred>] 
     107>>> User.objects.extra(select={'extra_field': 1}, order_by=['extra_field']).distinct() 
     108[<User: fred>] 
     109 
    101110"""}