Ticket #11916: ticket_11916.2.diff

File ticket_11916.2.diff, 1.8 KB (added by paluh, 5 years ago)

patch + test

  • django/db/models/sql/compiler.py

     
    484484                elif hasattr(col, 'as_sql'):
    485485                    result.append(col.as_sql(qn))
    486486                else:
    487                     result.append(str(col))
     487                    result.append('(%s)' % str(col))
    488488        return result, params
    489489
    490490    def fill_related_selections(self, opts=None, root_alias=None, cur_depth=1,
  • tests/regressiontests/aggregation_regress/models.py

     
    318318...
    319319FieldError: Cannot compute Avg('mean_age'): 'mean_age' is an aggregate
    320320
     321# Regression for 11916 - extra params + aggregation creates incorrect SQL
     322>>> shortest_book_sql = ' \\
     323... SELECT name \\
     324... FROM aggregation_regress_book b \\
     325... WHERE b.publisher_id = aggregation_regress_publisher.id \\
     326... ORDER BY b.pages \\
     327... LIMIT 1 '
     328>>> # tests that this query does not raise a DatabaseError due to the full
     329>>> # subselect being (erroneously) added to the GROUP BY parameters
     330>>> Publisher.objects.extra(select={
     331...     'name_of_shortest_book': shortest_book_sql,
     332... }).annotate(total_books=Count('book')).order_by('name').values_list('id', 'total_books', 'name_of_shortest_book')
     333[(1, 2, u'Practical Django Projects'), (5, 0, None), (4, 1, u'Paradigms of Artificial Intelligence Programming: Case Studies in Common Lisp'), (3, 2, u'Python Web Development with Django'), (2, 1, u'Sams Teach Yourself Django in 24 Hours')]
    321334"""
    322335}
    323336
Back to Top