﻿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
18247	Filtering on aggregate annotations with a Decimal value doesn't work	elmopl@…	Michael Tänzer	"When I run
{{{
$ python manage.py version
1.4
$ python manage.py shell
[...]
>>> for r in StoreBill.objects.annotate( amount = Sum('parts__amount') ).filter( date = '2012-03-28' ): r.amount
... 
Decimal('1.05')
>>> for r in StoreBill.objects.annotate( amount = Sum('parts__amount') ).filter( date = '2012-03-28', amount = Decimal(""1.05"") ): a = r.amount
... 
>>> print connection.queries[-1]
{'time': '0.002', 'sql': u'SELECT ""spendings_storebill"".""id"", ""spendings_storebill"".""name"", ""spendings_storebill"".""date"", SUM(""spendings_cost"".""amount"") AS ""amount"" FROM ""spendings_storebill"" LEFT OUTER JOIN ""spendings_storebillpart"" ON (""spendings_storebill"".""id"" = ""spendings_storebillpart"".""bill_id"") LEFT OUTER JOIN ""spendings_cost"" ON (""spendings_storebillpart"".""cost_ptr_id"" = ""spendings_cost"".""id"") WHERE (""spendings_storebill"".""date"" = 2012-03-28 ) GROUP BY ""spendings_storebill"".""id"", ""spendings_storebill"".""name"", ""spendings_storebill"".""date"" HAVING SUM(""spendings_cost"".""amount"") = 1.05 '}
}}}

As you can see from first query there is a result matching second one, yet I get no results for latter. If I run the generated query I get expected result (left only ""amount"" column):
{{{
sqlite> SELECT  SUM(""spendings_cost"".""amount"") AS ""amount"" FROM ""spendings_storebill"" LEFT OUTER JOIN ""spendings_storebillpart"" ON (""spendings_storebill"".""id"" = ""spendings_storebillpart"".""bill_id"") LEFT OUTER JOIN ""spendings_cost"" ON (""spendings_storebillpart"".""cost_ptr_id"" = ""spendings_cost"".""id"") GROUP BY ""spendings_storebill"".""id"", ""spendings_storebill"".""name"", ""spendings_storebill"".""date"" HAVING SUM(""spendings_cost"".""amount"") = 1.05  LIMIT 21;
1.05

}}}"	Bug	closed	Database layer (models, ORM)	dev	Normal	fixed	decimal filter annotate having	zbyte64 dylan@… Michael Tänzer	Ready for checkin	1	0	0	0	0	0
