#32786: Make the subquery ordering clearing optimization more selectively
-------------------------------------+-------------------------------------
     Reporter:  Hannes Ljungberg     |                    Owner:  Hannes
         Type:                       |  Ljungberg
  Cleanup/optimization               |                   Status:  closed
    Component:  Database layer       |                  Version:  dev
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:  fixed
     Keywords:                       |             Triage Stage:  Ready for
                                     |  checkin
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Andi Albrecht):

 Do I may bring up this issue again? I've stumbled upon a similar issue as
 reported in #32658 or #32786. Both were closed as invalid. However, this
 change added a test case to Django's main branch (which will be 4.0 if I'm
 not wrong) that tests a scenario that’s pretty similar to the code in the
 application I’m migrating from 2.2 LTS to 3.2 LTS. The test case looks
 totally legit to me and not like an abuse of the ORM:

 {{{
     def test_ordering_isnt_cleared_for_array_subquery(self):
         inner_qs = AggregateTestModel.objects.order_by('-integer_field')
         qs = AggregateTestModel.objects.annotate(
             integers=Func(
                 Subquery(inner_qs.values('integer_field')),
                 function='ARRAY',
                 output_field=ArrayField(base_field=IntegerField()),
             ),
         )
         self.assertSequenceEqual(
             qs.first().integers,
             inner_qs.values_list('integer_field', flat=True),
         )
 }}}

 When adding this test case to the Django 2.2 code base, the test passes.
 When adding it to 3.2 it fails due to the removal of ordering. Of course
 in main it passes too. So to me this looks like a regression in 3.2.

 I did a quick test and cherry-picked both changes form this ticket in my
 local 3.2 branch without much issues. Six tests in postgres_tests were
 failing because of different warnings, but the same six tests fail on a
 clean 3.2 branch on my machine too.

 Wouldn’t it be an option to backport these changes to 3.2 to have a
 consistent behavior in 2.2, 3.2 and the upcoming 4.x release?

-- 
Ticket URL: <https://code.djangoproject.com/ticket/32786#comment:9>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/067.0d3d28c1078a398fce71e8d2cd627c84%40djangoproject.com.

Reply via email to