Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#26498 closed Bug (fixed)

Data loss of microseconds on MySQL and SQLite

Reported by: Adam (Chainz) 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 Changed 4 years ago by Simon Charette

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

comment:3 Changed 4 years ago by Simon Charette

Triage Stage: AcceptedReady for checkin

comment:4 Changed 4 years ago by Tim Graham

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

comment:5 Changed 4 years ago by Adam (Chainz) Johnson

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

comment:6 Changed 4 years ago by Simon Charette

Patch needs improvement: set
Triage Stage: Ready for checkinAccepted

comment:7 Changed 4 years ago by Simon Charette

Version: master1.8

comment:8 Changed 4 years ago by Tim Graham <timograham@…>

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 Changed 4 years ago by Tim Graham <timograham@…>

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 Changed 4 years ago by Tim Graham <timograham@…>

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