Ticket #17144: group_by_bug_regressiontest.patch

File group_by_bug_regressiontest.patch, 1.6 KB (added by christian_oudard, 13 years ago)

Regression test for the issue

  • tests/regressiontests/aggregation_regress/tests.py

    diff --git a/tests/regressiontests/aggregation_regress/tests.py b/tests/regressiontests/aggregation_regress/tests.py
    index 1498f19..a8f3fcd 100644
    a b class AggregationTests(TestCase):  
    863863            ['Peter Norvig'],
    864864            lambda b: b.name
    865865        )
     866
     867    def test_aggregate_duplicate_columns(self):
     868        # Regression test for #17144
     869
     870        results = Author.objects.annotate(num_contacts=Count('book_contact_set'))
     871
     872        # There should only be one GROUP BY clause, for the `id` column.
     873        # `name` and `age` should not be grouped on.
     874        grouping, gb_params = results.query.get_compiler(using='default').get_grouping()
     875        self.assertEqual(len(grouping), 1)
     876        assert 'id' in grouping[0]
     877        assert 'name' not in grouping[0]
     878        assert 'age' not in grouping[0]
     879
     880        # The query group_by property should also only show the `id`.
     881        self.assertEqual(results.query.group_by, [('aggregation_regress', 'id')])
     882
     883        # Ensure that we get correct results.
     884        self.assertEqual(
     885            [(a.name, a.num_contacts) for a in results.order_by('name')],
     886            [
     887                ('Adrian Holovaty', 1),
     888                ('Brad Dayley', 1),
     889                ('Jacob Kaplan-Moss', 0),
     890                ('James Bennett', 1),
     891                ('Jeffrey Forcier', 1),
     892                ('Paul Bissex', 0),
     893                ('Peter Norvig', 2),
     894                ('Stuart Russell', 0),
     895                ('Wesley J. Chun', 0),
     896            ]
     897        )
Back to Top