Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#26498 closed Bug (fixed)

Data loss of microseconds on MySQL and SQLite

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

Description

Django provides django.db.backends.utils.typecast_time as a converter function for MySQL and SQLite. This function uses floating point logic which unfortunately causes loss of precision on some values, for example:

In [1]: from django.db.backends.utils import typecast_time

In [2]: typecast_time('12:45:30.126631')  # okay
Out[2]: datetime.time(12, 45, 30, 126631)

In [3]: typecast_time('12:45:30.126630')   # woops
Out[3]: datetime.time(12, 45, 30, 126629)

This will probably only cause loss of a single microsecond, but it's annoying that the database doesn't roundtrip values.

Change History (10)

comment:2 by Simon Charette, 9 years ago

Has patch: set
Triage Stage: UnreviewedAccepted
Type: UncategorizedBug
Version: 1.8master

comment:3 by Simon Charette, 9 years ago

Triage Stage: AcceptedReady for checkin

comment:4 by Tim Graham, 9 years ago

Should this be backported? Typically that's what we do for data loss issues.

comment:5 by Adam Johnson, 9 years ago

I'm hoping so, we've had to patchy.patch this in

comment:6 by Simon Charette, 9 years ago

Patch needs improvement: set
Triage Stage: Ready for checkinAccepted

comment:7 by Simon Charette, 9 years ago

Version: master1.8

comment:8 by Tim Graham <timograham@…>, 9 years ago

Resolution: fixed
Status: newclosed

In d3c87a24:

Fixed #26498 -- Fixed TimeField microseconds round-tripping on MySQL and SQLite.

Thanks adamchainz for the report and review.

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

In 0a411b22:

[1.8.x] Fixed #26498 -- Fixed TimeField microseconds round-tripping on MySQL and SQLite.

Thanks adamchainz for the report and review.

Backport of d3c87a2425b30400c3e6ea76585a9a537b6d0386 from master

comment:10 by Tim Graham <timograham@…>, 9 years ago

In 51400cb:

[1.9.x] Fixed #26498 -- Fixed TimeField microseconds round-tripping on MySQL and SQLite.

Thanks adamchainz for the report and review.

Backport of d3c87a2425b30400c3e6ea76585a9a537b6d0386 from master

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