diff options
author | Lukasz Wiecek <lukasz@yplanapp.com> | 2016-04-13 17:31:31 +0100 |
---|---|---|
committer | Tim Graham <timograham@gmail.com> | 2016-04-18 09:49:13 -0400 |
commit | 51400cbce8165d46fdd380e80a95b6248929b38b (patch) | |
tree | ddf6d6721fd51de053deb4b6d398df9b9811405f | |
parent | 12606d2b99dbfe7d0a8f51818e81a29ea2472943 (diff) | |
download | django-51400cbce8165d46fdd380e80a95b6248929b38b.tar.gz |
[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
-rw-r--r-- | django/db/backends/utils.py | 2 | ||||
-rw-r--r-- | docs/releases/1.8.13.txt | 3 | ||||
-rw-r--r-- | docs/releases/1.9.6.txt | 3 | ||||
-rw-r--r-- | tests/db_typecasts/tests.py | 3 |
4 files changed, 9 insertions, 2 deletions
diff --git a/django/db/backends/utils.py b/django/db/backends/utils.py index 84444548d3..87a51a4624 100644 --- a/django/db/backends/utils.py +++ b/django/db/backends/utils.py @@ -125,7 +125,7 @@ def typecast_time(s): # does NOT store time zone information seconds, microseconds = seconds.split('.') else: microseconds = '0' - return datetime.time(int(hour), int(minutes), int(seconds), int(float('.' + microseconds) * 1000000)) + return datetime.time(int(hour), int(minutes), int(seconds), int((microseconds + '000000')[:6])) def typecast_timestamp(s): # does NOT store time zone information diff --git a/docs/releases/1.8.13.txt b/docs/releases/1.8.13.txt index b1a3dd0c20..f725c37f99 100644 --- a/docs/releases/1.8.13.txt +++ b/docs/releases/1.8.13.txt @@ -9,4 +9,5 @@ Django 1.8.13 fixes several bugs in 1.8.12. Bugfixes ======== -* ... +* Fixed ``TimeField`` microseconds round-tripping on MySQL and SQLite + (:ticket:`26498`). diff --git a/docs/releases/1.9.6.txt b/docs/releases/1.9.6.txt index bf2e61a5c1..c22e99f48e 100644 --- a/docs/releases/1.9.6.txt +++ b/docs/releases/1.9.6.txt @@ -12,3 +12,6 @@ Bugfixes * Added support for relative path redirects to ``SimpleTestCase.assertRedirects()`` because Django 1.9 no longer converts redirects to absolute URIs (:ticket:`26428`). + +* Fixed ``TimeField`` microseconds round-tripping on MySQL and SQLite + (:ticket:`26498`). diff --git a/tests/db_typecasts/tests.py b/tests/db_typecasts/tests.py index 98748abee4..fa9eab164d 100644 --- a/tests/db_typecasts/tests.py +++ b/tests/db_typecasts/tests.py @@ -27,6 +27,9 @@ TEST_CASES = { ('00:00:12', datetime.time(0, 0, 12)), ('00:00:12.5', datetime.time(0, 0, 12, 500000)), ('7:22:13.312', datetime.time(7, 22, 13, 312000)), + ('12:45:30.126631', datetime.time(12, 45, 30, 126631)), + ('12:45:30.126630', datetime.time(12, 45, 30, 126630)), + ('12:45:30.123456789', datetime.time(12, 45, 30, 123456)), ), 'typecast_timestamp': ( ('', None), |