#26324: DurationField stores certain values incorrectly in sqlite
-------------------------------------+-------------------------------------
Reporter: chausner | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: sqlite, | Triage Stage: Accepted
DurationField |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Neraste):
I am currently running into the very same problem (Django 1.8.6).
The {{{get_db_prep_value}}} method of {{{DurationField}}} class always
returns a float to the database:
{{{#!python
return value.total_seconds() * 1000000
}}}
Analyzing Django debug logs shows the SQLite driver always receive float
values. Some are harmless (eg: 119019000.0), others are harmfull (eg:
133592000.00000001). The last ones come from the funny side effects of
floating computation:
{{{
>>> 133.592 * 1000000
133592000.00000001
}}}
I think it can be fixed with:
{{{#!python
return int(round(value.total_seconds() * 1000000))
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26324#comment:4>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/066.91ede137638c82aa73267ad833e2bd46%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.