#32096: Using KeyTransform in ArrayAgg function produces invalid SQL
-------------------------------------+-------------------------------------
               Reporter:  Igor       |          Owner:  nobody
  Jerosimić                          |
                   Type:  Bug        |         Status:  new
              Component:  Database   |        Version:  3.1
  layer (models, ORM)                |
               Severity:  Normal     |       Keywords:
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 Using `KeyTransform` in `ordering` attribute of `ArrayAgg` function
 produces invalid SQL.

 {{{
 #!python
 # sample model
 from django.db import models

 class Parent(models.Model):
     name = models.CharField(default='test')

 class Child(models.Model):
     parent = models.ForeignKey(
         Parent,
         on_delete=models.SET_NULL,
         related_name='children',
     )
     data = models.JSONField(default=dict)


 # sample data
 parent = Parent.objects.create()
 Child.objects.create(parent=parent, data={'en': 'English', 'fr':
 'French'})


 # error
 Parent.objects.annotate(
         children_array=ArrayAgg(
                 KeyTextTransform('en', 'children__data'),
                 distinct=True,
                 ordering=[KeyTransform('en', 'children__data')],
         ),
 ).all()
 }}}

 Produces invalid SQL in the ORDER BY section:
 {{{
 ARRAY_AGG(DISTINCT ("children"."data" ->> 'default') ORDER BY
 None("children"."data"))
 }}}

 NOTE: This was working fine before Django 3.1.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/32096>
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/051.885b8f0bf61952a61af2c47fa841bbbd%40djangoproject.com.

Reply via email to