summaryrefslogtreecommitdiff
path: root/tests/aggregation_regress
diff options
context:
space:
mode:
authorMichael Tänzer <neo@nhng.de>2015-06-07 02:05:36 +0200
committerTim Graham <timograham@gmail.com>2015-06-30 18:27:42 -0400
commit3bbaf84d6533fb61ac0038f2bbe52ee0d7b4fd10 (patch)
tree215672c8af92ac82e9995e2cb1cb10f291745f79 /tests/aggregation_regress
parentb64c0d4d613b5cabedbc9b847682fe14877537de (diff)
Fixed #18247 -- Added cast to NUMERIC for Decimals on sqlite
On sqlite the SUM() of a decimal column doesn't have a NUMERIC type so when comparing it to a string literal (which a Decimal gets converted to in Django) it is not compared as expected.
Diffstat (limited to 'tests/aggregation_regress')
-rw-r--r--tests/aggregation_regress/tests.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/tests/aggregation_regress/tests.py b/tests/aggregation_regress/tests.py
index cb469363a0..1e680dbdd9 100644
--- a/tests/aggregation_regress/tests.py
+++ b/tests/aggregation_regress/tests.py
@@ -349,6 +349,20 @@ class AggregationTests(TestCase):
{'c__max': 3}
)
+ def test_decimal_aggregate_annotation_filter(self):
+ """
+ Filtering on an aggregate annotation with Decimal values should work.
+ Requires special handling on SQLite (#18247).
+ """
+ self.assertEqual(
+ len(Author.objects.annotate(sum=Sum('book_contact_set__price')).filter(sum__gt=Decimal(40))),
+ 1
+ )
+ self.assertEqual(
+ len(Author.objects.annotate(sum=Sum('book_contact_set__price')).filter(sum__lte=Decimal(40))),
+ 4
+ )
+
def test_field_error(self):
# Bad field requests in aggregates are caught and reported
self.assertRaises(