diff --git a/tests/queries/tests.py b/tests/queries/tests.py index 59f9a5c177..5163fc5cb1 100644 --- a/tests/queries/tests.py +++ b/tests/queries/tests.py @@ -392,6 +392,20 @@ class Queries1Tests(TestCase): qs = qs.order_by("id") self.assertNotIn("OUTER JOIN", str(qs.query)) + def test_order_by_related_field_transform(self): + extra_12 = ExtraInfo.objects.create( + info="extra 12", + date=DateTimePK.objects.create(date=datetime.datetime(2021, 12, 10)), + ) + extra_11 = ExtraInfo.objects.create( + info="extra 11", + date=DateTimePK.objects.create(date=datetime.datetime(2022, 11, 10)), + ) + self.assertSequenceEqual( + ExtraInfo.objects.filter(date__isnull=False).order_by("date__month"), + [extra_11, extra_12], + ) + def test_filter_by_related_field_transform(self): extra_old = ExtraInfo.objects.create( info="extra 12",