﻿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
34987	"""Expression contains mixed types"" exception when performing window function on query that also has aggregates."	ElRoberto538	Simon Charette	"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.
"	Bug	closed	Database layer (models, ORM)	4.2	Release blocker	fixed	Expression, Window, aggregate, annotation, partition	Simon Charette	Accepted	1	0	0	0	0	0
