Ticket #11916: ticket_11916.3.diff
File ticket_11916.3.diff, 2.1 KB (added by , 15 years ago) |
---|
-
django/db/models/sql/compiler.py
484 484 elif hasattr(col, 'as_sql'): 485 485 result.append(col.as_sql(qn)) 486 486 else: 487 result.append( str(col))487 result.append('(%s)' % str(col)) 488 488 return result, params 489 489 490 490 def fill_related_selections(self, opts=None, root_alias=None, cur_depth=1, -
tests/regressiontests/aggregation_regress/tests.py
1 from django.conf import settings 1 2 from django.test import TestCase 2 from django.db.models import Max 3 from django.db import DEFAULT_DB_ALIAS 4 from django.db.models import Count, Max 3 5 4 6 from regressiontests.aggregation_regress.models import * 5 7 … … 46 48 qs1 = books.filter(id__in=qs) 47 49 qs2 = books.filter(id__in=list(qs)) 48 50 self.assertEqual(list(qs1), list(qs2)) 51 52 def test_annotate_with_extra(self): 53 """ 54 Regression test for #11916: Extra params + aggregation creates 55 incorrect SQL. 56 """ 57 #oracle doesn't support subqueries in group by clause 58 if settings.DATABASES[DEFAULT_DB_ALIAS]['ENGINE'] == 'django.db.backends.oracle': 59 return 60 shortest_book_sql = """ 61 SELECT name 62 FROM aggregation_regress_book b 63 WHERE b.publisher_id = aggregation_regress_publisher.id 64 ORDER BY b.pages 65 LIMIT 1 66 """ 67 # tests that this query does not raise a DatabaseError due to the full 68 # subselect being (erroneously) added to the GROUP BY parameters 69 qs = Publisher.objects.extra(select={ 70 'name_of_shortest_book': shortest_book_sql, 71 }).annotate(total_books=Count('book')) 72 # force execution of the query 73 list(qs)