Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Changed Query.get_columns() to quote the 'AS' column names in an extr…

…a_select situation, to match pre-queryset-refactor behavior. Added unit tests that verify this and provide an example

git-svn-id: http://code.djangoproject.com/svn/django/trunk@7502 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 14d6ee2dc956d06fc1014e1b3c1f1410d553157d 1 parent 13a6fd6
@adrianholovaty adrianholovaty authored
Showing with 14 additions and 1 deletion.
  1. +2 −1  django/db/models/sql/query.py
  2. +12 −0 tests/modeltests/basic/models.py
View
3  django/db/models/sql/query.py
@@ -394,7 +394,8 @@ def get_columns(self, with_aliases=False):
some cases to avoid ambiguitity with nested queries.
"""
qn = self.quote_name_unless_alias
- result = ['(%s) AS %s' % (col, alias) for alias, col in self.extra_select.iteritems()]
+ qn2 = self.connection.ops.quote_name
+ result = ['(%s) AS %s' % (col, qn2(alias)) for alias, col in self.extra_select.iteritems()]
aliases = set(self.extra_select.keys())
if with_aliases:
col_aliases = aliases.copy()
View
12 tests/modeltests/basic/models.py
@@ -398,4 +398,16 @@ def __unicode__(self):
>>> s = set([a10, a11, a12])
>>> Article.objects.get(headline='Article 11') in s
True
+
+# The 'select' argument to extra() supports names with dashes in them, as long
+# as you use values().
+>>> Article.objects.filter(pub_date__year=2008).extra(select={'dashed-value': '1'}).values('headline', 'dashed-value')
+[{'headline': u'Article 11', 'dashed-value': 1}, {'headline': u'Article 12', 'dashed-value': 1}]
+
+# If you use 'select' with extra() and names containing dashes on a query
+# that's *not* a values() query, those extra 'select' values will silently be
+# ignored.
+>>> articles = Article.objects.filter(pub_date__year=2008).extra(select={'dashed-value': '1', 'undashedvalue': '2'})
+>>> articles[0].undashedvalue
+2
"""
Please sign in to comment.
Something went wrong with that request. Please try again.