Author: mtredinnick
Date: 2008-09-02 22:48:25 -0500 (Tue, 02 Sep 2008)
New Revision: 8898

Modified:
   django/trunk/django/db/models/sql/query.py
   django/trunk/tests/regressiontests/extra_regress/models.py
Log:
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.


Modified: django/trunk/django/db/models/sql/query.py
===================================================================
--- django/trunk/django/db/models/sql/query.py  2008-09-03 02:49:06 UTC (rev 
8897)
+++ django/trunk/django/db/models/sql/query.py  2008-09-03 03:48:25 UTC (rev 
8898)
@@ -630,7 +630,7 @@
             else:
                 col, order = get_order_dir(field, asc)
                 elt = qn2(col)
-                if distinct and elt not in select_aliases:
+                if distinct and col not in select_aliases:
                     ordering_aliases.append(elt)
                 result.append('%s %s' % (elt, order))
         self.ordering_aliases = ordering_aliases

Modified: django/trunk/tests/regressiontests/extra_regress/models.py
===================================================================
--- django/trunk/tests/regressiontests/extra_regress/models.py  2008-09-03 
02:49:06 UTC (rev 8897)
+++ django/trunk/tests/regressiontests/extra_regress/models.py  2008-09-03 
03:48:25 UTC (rev 8898)
@@ -98,4 +98,13 @@
 >>> Order.objects.extra(where=["username=%s"], params=["fred"], 
 >>> tables=["auth_user"]).order_by('created_by')
 []
 
+# Regression test for #8819: Fields in the extra(select=...) list should be
+# available to extra(order_by=...).
+>>> User.objects.extra(select={'extra_field': 1}).distinct()
+[<User: fred>]
+>>> User.objects.extra(select={'extra_field': 1}, order_by=['extra_field'])
+[<User: fred>]
+>>> User.objects.extra(select={'extra_field': 1}, 
order_by=['extra_field']).distinct()
+[<User: fred>]
+
 """}


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to