﻿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
20216	filtering over an Sum on a BooleanField uses BooleanField's get_db_prep_lookup on the value	Pavel Anossov	nobody	"With a model like this:

{{{

class Test(models.Model):
    active = models.BooleanField()
    group = models.IntegerField()

}}}

this queryset:

`Test.objects.values('group').annotate(s=Sum('active')).filter(s__gt=123456)`

As well as this one, and one with any other value

`Test.objects.values('group').annotate(s=Sum('active')).filter(s__gt='wharrgabl')`

Generates this SQL and params

`SELECT ""test_test"".""group"", SUM(""test_test"".""active"") AS ""s"" FROM ""test_test"" GROUP BY ""test_test"".""group"" HAVING SUM(""test_test"".""active"") > ?  LIMIT 21`

`(True,)`

That is, any value is converted to `bool` by `BooleanField`'s `get_db_prep_lookup` called from [https://github.com/django/django/blob/master/django/db/models/sql/where.py#L183 here].
"	Bug	closed	Database layer (models, ORM)	1.5	Normal	invalid			Unreviewed	0	0	0	0	0	0
