﻿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
34024	'WhereNode' object has no attribute 'is_summary' when counting a queryset with annotation from a subquery	Valentin Rigal	David Sanders	"I reproduced on a blank project (4.0 and 4.1 with a Postgres database) using this use case:

`models.py`
{{{
class School(models.Model):
    """"""A school""""""

class Director(models.Model):
    school = models.ForeignKey(School, on_delete=models.CASCADE)                        
    speciality = models.CharField(max_length=200)
}}}

It is not possible to run this code:
{{{#!python
>>> School.objects.annotate(
>>>     speciality=Subquery(Director.objects.values('speciality')[:1]),
>>>     has_speciality=Q(speciality__isnull=False)
>>> ).count()
…
AttributeError: 'WhereNode' object has no attribute 'is_summary'
}}}

Reverting this precise commit seems to fix the issue : https://github.com/django/django/commit/b64db05b9cedd96905d637a2d824cbbf428e40e7

The request is a bit exotic, I don't know if it should be supported.
This is the first ticket I open, I can clarify/submit a merge request if needed."	Bug	closed	Database layer (models, ORM)	4.1	Normal	fixed		David Sanders David Wobrock	Accepted	1	0	0	0	0	0
