From ba9a2b754452b542d3f472f0acce6f940911aced Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Wed, 10 Mar 2021 09:16:28 +0100 Subject: Refs #32508 -- Raised TypeError instead of using "assert" on unsupported operations for sliced querysets. --- tests/distinct_on_fields/tests.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'tests/distinct_on_fields') diff --git a/tests/distinct_on_fields/tests.py b/tests/distinct_on_fields/tests.py index 34d4509cec..f87a3affb3 100644 --- a/tests/distinct_on_fields/tests.py +++ b/tests/distinct_on_fields/tests.py @@ -98,6 +98,11 @@ class DistinctOnTests(TestCase): c2 = c1.distinct('pk') self.assertNotIn('OUTER JOIN', str(c2.query)) + def test_sliced_queryset(self): + msg = 'Cannot create distinct fields once a slice has been taken.' + with self.assertRaisesMessage(TypeError, msg): + Staff.objects.all()[0:5].distinct('name') + def test_transform(self): new_name = self.t1.name.upper() self.assertNotEqual(self.t1.name, new_name) -- cgit v1.3