﻿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
21208	"invalid reference to FROM-clause"" for nested annotate query"	jaromudr@…	nobody	"Issue is very similar to #10182 wich was closed, the difference is only that I use extra query.
So I have next code:
{{{
    where = """"""            
            (setweight(to_tsvector('pg_catalog.english', coalesce(""event_event"".""name"", ""event_event"".""description"")), 'D')) @@ plainto_tsquery('pg_catalog.english', %s)
            OR (setweight(to_tsvector('pg_catalog.english', coalesce(""event_singleevent"".""description"", '')), 'D')) @@ plainto_tsquery('pg_catalog.english', %s)
    """"""

    events = qs.extra(
        where=[where],
        params=[search_string, search_string]
    )
}}}

What I want to do is to select all tags from this events. 

To do that I use next query
{{{
   tags = TaggedItem.objects.filter(object_id__in=events.values_list(""event_id"", flat=True)) 
}}}

and I got error 
invalid reference to FROM-clause entry for table ""event_event""
HINT:  Perhaps you meant to reference the table alias ""u3"".

That occured because when we use such syntax django start subquery with 
{{{
    SELECT U0.""event_id"" FROM ""event_singleevent"" U0 ...
}}}

I able to fix this error only next way:
{{{
    tags = TaggedItem.objects.filter(object_id__in=map(lambda event: event.event.id, events))
}}}
this solution have bad performance.

Please, can you give me some advise?

Environment: Django (1, 5, 2, 'final', 0) / PostgreSQL"	Uncategorized	closed	Database layer (models, ORM)	1.5	Normal	wontfix			Unreviewed	0	0	0	0	0	0
