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):
|
483 | 483 | params.extend(extra_params) |
484 | 484 | cols = (group_by + self.query.select + |
485 | 485 | self.query.related_select_cols + extra_selects) |
| 486 | seen = set() |
486 | 487 | for col in cols: |
| 488 | if col in seen: |
| 489 | continue |
| 490 | seen.add(col) |
487 | 491 | if isinstance(col, (list, tuple)): |
488 | 492 | result.append('%s.%s' % (qn(col[0]), qn(col[1]))) |
489 | 493 | elif hasattr(col, 'as_sql'): |
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):
|
462 | 462 | lambda b: b.name |
463 | 463 | ) |
464 | 464 | |
| 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 | |
465 | 471 | def test_duplicate_alias(self): |
466 | 472 | # Regression for #11256 - duplicating a default alias raises ValueError. |
467 | 473 | self.assertRaises(ValueError, Book.objects.all().annotate, Avg('authors__age'), authors__age__avg=Avg('authors__age')) |