﻿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
31109	Multiple annotation with Subquery generates wrong SQL.	Thierry Bastian	Simon Charette	"I have 2 models Item and ItemInfo.


{{{
class Item(models.Model):
    name = TextField()
    ...

class ItemInfo(models.Model):
    id = models.OneToOneField(Item, models.CASCADE, db_column='id', primary_key=True)
    size = models.BigIntegerField(blank=True, null=True)
    ...
}}}



If I do a QuerySet like this:
{{{
        Item.objects \
            .annotate(
            size=Subquery(
                ItemInfo.objects.filter(id=OuterRef('id')).values_list(
                    'size', flat=True
                )[:1]
            ),
            depends_on=StringAgg('name', ', ' )
        )
}}}


If I simply execute it, it works. Please don't look at the QuerySet, I really tried to make it the simplest example ever
But if I do a .exists() I'm getting 

django.db.utils.ProgrammingError: column ""size"" does not exist
LINE 1...

Obviously that used to work with any 2.x version."	Bug	closed	Database layer (models, ORM)	3.0	Release blocker	fixed		Simon Charette	Accepted	1	0	0	0	0	0
