"Expression contains mixed types" exception when performing window function on query that also has aggregates.
We're currently upgrading from Django 3.2.x -> 4.2.7 and have encountered a weird bug when using both Window functions and aggregates in a query annotation, the example below works fine in Django 3.2. For now I've cast all the fields in the Window partition to CharField, but it's a bit of a hack... I tested this with both mssql and sqlite connectors.
class TestModel(models.Model):
field_1 = models.IntegerField()
field_2 = models.IntegerField()
field_3 = models.DateField()
TestModel.objects.annotate(
xyz=Window(
expression=Sum('field_1'),
partition_by=[F('field_2'), F('field_3')]
),
yxz=Max('field_2')
)
django.core.exceptions.FieldError: Expression contains mixed types: AutoField, DateField. You must set output_field.
Change History
(7)
Cc: |
Simon Charette added
|
Triage Stage: |
Unreviewed → Accepted
|
Severity: |
Normal → Release blocker
|
Owner: |
changed from nobody to Simon Charette
|
Status: |
new → assigned
|
Resolution: |
→ fixed
|
Status: |
assigned → closed
|
Hi ElRoberto538,
Thanks for the report 🏆
Bisected to f387d024fc75569d2a4a338bfda76cc2f328f627
@Simon ticket appears similar to #34717 which is fixed, though can still replicate this issue on main.