Permalink
Browse files

Fixed #8819 -- Don't include two copies of extra-select columns in th…

…e 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.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@8898 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent d2ca6fd commit 61cc4a1eeefe734e258c968293529ab070d4d76a @malcolmt malcolmt committed Sep 3, 2008
Showing with 10 additions and 1 deletion.
  1. +1 −1 django/db/models/sql/query.py
  2. +9 −0 tests/regressiontests/extra_regress/models.py
@@ -630,7 +630,7 @@ def get_ordering(self):
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
@@ -98,4 +98,13 @@ class Order(models.Model):
>>> 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>]
+
"""}

0 comments on commit 61cc4a1

Please sign in to comment.