mirror of
https://github.com/django/django.git
synced 2025-08-03 18:38:50 +00:00
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.
This commit is contained in:
parent
b64c0d4d61
commit
3bbaf84d65
2 changed files with 23 additions and 0 deletions
|
@ -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(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue