Opened 6 years ago

Closed 6 years ago

#28926 closed Bug (fixed)

some big values of DurationField are saved inaccurately on SQLite and MySQL

Reported by: Sergey Fedoseev Owned by: Sergey Fedoseev
Component: Database layer (models, ORM) Version: 1.8
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

class TestSaveLoad(TestCase):

    def test_simple_roundtrip(self):
        duration = datetime.timedelta(microseconds=674999999999999999)
        DurationModel.objects.create(field=duration)
        loaded = DurationModel.objects.get()
        self.assertEqual(loaded.field, duration)
======================================================================
FAIL: test_simple_roundtrip (model_fields.test_durationfield.TestSaveLoad)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python3.6/unittest/case.py", line 59, in testPartExecutor
    yield
  File "/usr/lib/python3.6/unittest/case.py", line 605, in run
    testMethod()
  File "/home/sergey/dev/django/tests/model_fields/test_durationfield.py", line 18, in test_simple_roundtrip
    self.assertEqual(loaded.field, duration)
  File "/usr/lib/python3.6/unittest/case.py", line 829, in assertEqual
    assertion_func(first, second, msg=msg)
  File "/usr/lib/python3.6/unittest/case.py", line 822, in _baseAssertEqual
    raise self.failureException(msg)
AssertionError: datetime.timedelta(7812500) != datetime.timedelta(7812499, 86399, 999999)

Change History (5)

comment:1 by Sergey Fedoseev, 6 years ago

Owner: changed from nobody to Sergey Fedoseev
Status: newassigned

comment:2 by Sergey Fedoseev, 6 years ago

comment:3 by Simon Charette, 6 years ago

Triage Stage: UnreviewedAccepted

comment:4 by Tim Graham, 6 years ago

Has patch: set

comment:5 by Tim Graham <timograham@…>, 6 years ago

Resolution: fixed
Status: assignedclosed

In ae6fa914:

Fixed #28926 -- Fixed loss of precision of big DurationField values on SQLite and MySQL.

Note: See TracTickets for help on using tickets.
Back to Top