Opened 4 years ago
Last modified 4 years ago
#32096 closed Bug
Using KeyTransform in ArrayAgg function produces invalid SQL — at Initial Version
Reported by: | Igor Jerosimić | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 3.1 |
Severity: | Release blocker | Keywords: | KeyTransform, ArrayAgg |
Cc: | Sage Abdullah | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Using KeyTransform
in ordering
attribute of ArrayAgg
function produces invalid SQL.
# 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.
Note:
See TracTickets
for help on using tickets.