﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
32096	Using KeyTransform in ArrayAgg function produces invalid SQL	Igor Jerosimić	nobody	"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."	Bug	new	Database layer (models, ORM)	3.1	Normal				Unreviewed	0	0	0	0	0	0
