﻿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
28826	AttributeError while trying to filter by annotion based on Q	Ilya	nobody	"{{{
class HumansManager(models.Manager):
    def get_queryset(self):
        wrapper = ExpressionWrapper(Q(payments__gt=F('salary')), output_field=models.BooleanField())
        return models.QuerySet(self.model).annotate(is_in_trouble=wrapper)


class Human(models.Model):
    salary = models.IntegerField()
    payments = models.IntegerField()
    objects = HumansManager()
}}}

`is_in_trouble` works for
* `Human.objects.first().is_in_trouble`
* `Human.objects.values('is_in_trouble')`
But
`Human.objects.filter(is_in_trouble=True)` leads to
{{{
  File ""C:\spam\Python36-32\lib\site-packages\django\db\models\query.py"", line 246, in __repr__
    data = list(self[:REPR_OUTPUT_SIZE + 1])
  File ""C:\spam\Python36-32\lib\site-packages\django\db\models\query.py"", line 270, in __iter__
    self._fetch_all()
  File ""C:\spam\Python36-32\lib\site-packages\django\db\models\query.py"", line 1178, in _fetch_all
    self._result_cache = list(self._iterable_class(self))
  File ""C:\spam\Python36-32\lib\site-packages\django\db\models\query.py"", line 55, in __iter__
    results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
  File ""C:\spam\Python36-32\lib\site-packages\django\db\models\sql\compiler.py"", line 1049, in execute_sql
    sql, params = self.as_sql()
  File ""C:\spam\Python36-32\lib\site-packages\django\db\models\sql\compiler.py"", line 458, in as_sql
    where, w_params = self.compile(self.where) if self.where is not None else ("""", [])
  File ""C:\spam\Python36-32\lib\site-packages\django\db\models\sql\compiler.py"", line 390, in compile
    sql, params = node.as_sql(self, self.connection)
  File ""C:\spam\Python36-32\lib\site-packages\django\db\models\sql\where.py"", line 79, in as_sql
    sql, params = compiler.compile(child)
  File ""C:\spam\Python36-32\lib\site-packages\django\db\models\sql\compiler.py"", line 390, in compile
    sql, params = node.as_sql(self, self.connection)
  File ""C:\spam\Python36-32\lib\site-packages\django\db\models\lookups.py"", line 160, in as_sql
    lhs_sql, params = self.process_lhs(compiler, connection)
  File ""C:\spam\Python36-32\lib\site-packages\django\db\models\lookups.py"", line 151, in process_lhs
    lhs_sql, params = super().process_lhs(compiler, connection, lhs)
  File ""C:\spam\Python36-32\lib\site-packages\django\db\models\lookups.py"", line 77, in process_lhs
    lhs = lhs.resolve_expression(compiler.query)
  File ""C:\spam\Python36-32\lib\site-packages\django\db\models\expressions.py"", line 248, in resolve_expression
    for expr in c.get_source_expressions()
  File ""C:\spam\Python36-32\lib\site-packages\django\db\models\expressions.py"", line 248, in <listcomp>
    for expr in c.get_source_expressions()
AttributeError: 'WhereNode' object has no attribute 'resolve_expression'
}}}

It really confusing. "	Bug	closed	Database layer (models, ORM)	dev	Normal	duplicate			Unreviewed	0	0	0	0	0	0
