mirror of
https://github.com/django/django.git
synced 2025-10-23 21:59:11 +00:00
Fixed #28967 -- Prevented Cast to FloatField from rounding to integer on MySQL.
This commit is contained in:
committed by
Tim Graham
parent
f1aa58479c
commit
44908d4d93
@@ -1,4 +1,5 @@
|
||||
import datetime
|
||||
import decimal
|
||||
|
||||
from django.db import models
|
||||
from django.db.models.expressions import Value
|
||||
@@ -55,5 +56,7 @@ class CastTests(TestCase):
|
||||
self.assertEqual(dates.get().cast_datetime, now)
|
||||
|
||||
def test_cast_from_python(self):
|
||||
numbers = Author.objects.annotate(cast_float=Cast(0, models.FloatField()))
|
||||
self.assertEqual(numbers.get().cast_float, 0.0)
|
||||
numbers = Author.objects.annotate(cast_float=Cast(decimal.Decimal(0.125), models.FloatField()))
|
||||
cast_float = numbers.get().cast_float
|
||||
self.assertIsInstance(cast_float, float)
|
||||
self.assertEqual(cast_float, 0.125)
|
||||
|
||||
Reference in New Issue
Block a user