Ticket #15709: 15709.diff

File 15709.diff, 1.6 KB (added by Matthias Kestenholz, 13 years ago)
  • django/db/models/sql/compiler.py

    diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py
    index d425c8b..b1c5f4c 100644
    a b class SQLCompiler(object):  
    483483                params.extend(extra_params)
    484484            cols = (group_by + self.query.select +
    485485                self.query.related_select_cols + extra_selects)
     486            seen = set()
    486487            for col in cols:
     488                if col in seen:
     489                    continue
     490                seen.add(col)
    487491                if isinstance(col, (list, tuple)):
    488492                    result.append('%s.%s' % (qn(col[0]), qn(col[1])))
    489493                elif hasattr(col, 'as_sql'):
  • tests/regressiontests/aggregation_regress/tests.py

    diff --git a/tests/regressiontests/aggregation_regress/tests.py b/tests/regressiontests/aggregation_regress/tests.py
    index 0bb6899..1410421 100644
    a b class AggregationTests(TestCase):  
    462462            lambda b: b.name
    463463        )
    464464
     465        # Regression for #15709 - Ensure each group_by field only exists once
     466        # per query
     467        qs = Book.objects.values('publisher').annotate(max_pages=Max('pages')).order_by()
     468        grouping, gb_params = qs.query.get_compiler(qs.db).get_grouping()
     469        self.assertEqual(len(grouping), 1)
     470
    465471    def test_duplicate_alias(self):
    466472        # Regression for #11256 - duplicating a default alias raises ValueError.
    467473        self.assertRaises(ValueError, Book.objects.all().annotate, Avg('authors__age'), authors__age__avg=Avg('authors__age'))
Back to Top