mirror of
https://github.com/django/django.git
synced 2025-07-19 09:09:13 +00:00
[1.8.x] Fixed #26324 -- Fixed DurationField with fractional seconds on SQLite.
Backport of 4f0cd0fd162122da96978b357ac9fc9534529410 from master
This commit is contained in:
parent
ae4d932b1a
commit
c7764ca3a0
@ -1680,7 +1680,8 @@ class DurationField(Field):
|
|||||||
return value
|
return value
|
||||||
if value is None:
|
if value is None:
|
||||||
return None
|
return None
|
||||||
return value.total_seconds() * 1000000
|
# Discard any fractional microseconds due to floating point arithmetic.
|
||||||
|
return int(round(value.total_seconds() * 1000000))
|
||||||
|
|
||||||
def get_db_converters(self, connection):
|
def get_db_converters(self, connection):
|
||||||
converters = []
|
converters = []
|
||||||
|
@ -12,3 +12,6 @@ Bugfixes
|
|||||||
* Made ``MultiPartParser`` ignore filenames that normalize to an empty string
|
* Made ``MultiPartParser`` ignore filenames that normalize to an empty string
|
||||||
to fix crash in ``MemoryFileUploadHandler`` on specially crafted user input
|
to fix crash in ``MemoryFileUploadHandler`` on specially crafted user input
|
||||||
(:ticket:`26325`).
|
(:ticket:`26325`).
|
||||||
|
|
||||||
|
* Fixed data loss on SQLite where ``DurationField`` values with fractional
|
||||||
|
seconds could be saved as ``None`` (:ticket:`26324`).
|
||||||
|
@ -22,6 +22,12 @@ class TestSaveLoad(TestCase):
|
|||||||
loaded = NullDurationModel.objects.get()
|
loaded = NullDurationModel.objects.get()
|
||||||
self.assertEqual(loaded.field, None)
|
self.assertEqual(loaded.field, None)
|
||||||
|
|
||||||
|
def test_fractional_seconds(self):
|
||||||
|
value = datetime.timedelta(seconds=2.05)
|
||||||
|
d = DurationModel.objects.create(field=value)
|
||||||
|
d.refresh_from_db()
|
||||||
|
self.assertEqual(d.field, value)
|
||||||
|
|
||||||
|
|
||||||
class TestQuerying(TestCase):
|
class TestQuerying(TestCase):
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user