#34987 closed Bug (fixed)
"Expression contains mixed types" exception when performing window function on query that also has aggregates.
Description ¶
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)
comment:1 by , 16 months ago
Cc: | added |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 16 months ago
Severity: | Normal → Release blocker |
---|
Settings as release blocker since the bisected revision was released in 4.2a1
comment:3 by , 16 months ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
I'm pretty sure that the issue is due to Window
's output field resolving is considering partition_by
as part of its output when it shouldn't.
comment:4 by , 16 months ago
Has patch: | set |
---|
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.