﻿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
30683	QuerySet.count() crashes when window functions and conditional expressions are both used.	Adam Sołtysik	nobody	"Any `count()` query with window functions inside conditional expressions, like:

{{{Model.objects.annotate(rank=Case(When(condition=~Q(pk=None), then=Window(Rank(), order_by=F('pk'))))).count()}}}

throws an error:

{{{django.db.utils.ProgrammingError: window functions are not allowed in GROUP BY}}}

The query works after adding `.values('pk')` to it or when conditional expressions are not used.

There is a similar inconsistency when we call e.g. `.filter(rank__gt=0)` instead of `.count()`. It doesn't work anyway (#28333), but there are two different errors depending on whether conditionals are used: `django.db.utils.ProgrammingError: window functions are not allowed in WHERE` or `django.db.utils.NotSupportedError: Window is disallowed in the filter clause.`.



"	Bug	closed	Database layer (models, ORM)	dev	Normal	duplicate			Unreviewed	0	0	0	0	0	0
