Before any changes, with this combination, when saving the date
`2008-12-31 23:59:59.999999` the database result is rounded to `2009-01-01
00:00:00`. However, (to my understanding) Django expects the date to be
truncated, not rounded.
Additionally, MySQL INTERVAL would promote a datetime without microseconds
to a datetime with microseconds if the INTERVAL was a float or contained
microseconds. Older MySQLdb was unable to properly parse the result to a
Python datetime.
FWIW, I ran into this using the system libraries of a default Fedora 21
install. Fedora 21 ships with following versions:
community-mysql-server-5.6.23-1.fc21.x86_64
MySQL-python-1.2.3-13.fc21.x86_64
Individuals can workaround this by using virtualenv to install a newer
MySQLdb or mysqlclient.
The following tests fail before any changes:
{{{
======================================================================
FAIL: test_mixed_type_annotation_date_interval
(annotations.tests.NonAggregateAnnotationTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/jon/devel/django/tests/annotations/tests.py", line 147, in
test_mixed_type_annotation_date_interval
self.assertEqual(t.expires, expires)
AssertionError: None != datetime.datetime(2015, 3, 20, 15, 0)
======================================================================
FAIL: test_get_next_prev_by_field (model_regress.tests.ModelTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/jon/devel/django/tests/model_regress/tests.py", line 178, in
test_get_next_prev_by_field
e.get_previous_by_when().when, datetime.datetime(2000, 1, 1, 6, 1, 1)
AssertionError: datetime.datetime(2000, 1, 1, 12, 0, 20) !=
datetime.datetime(2000, 1, 1, 6, 1, 1)
======================================================================
FAIL: test_mixed_comparisons1 (expressions.tests.FTimeDeltaTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/jon/devel/django/django/test/testcases.py", line 1023, in
skip_wrapper
return test_func(*args, **kwargs)
File "/home/jon/devel/django/tests/expressions/tests.py", line 765, in
test_mixed_comparisons1
self.assertEqual(test_set, self.expnames[:i + 1])
AssertionError: Lists differ: [] != [u'e0']
Second list contains 1 additional elements.
First extra element 0:
e0
- []
+ [u'e0']
======================================================================
FAIL: test_extra_method_select_argument_with_dashes_and_values
(basic.tests.ModelTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/jon/devel/django/tests/basic/tests.py", line 304, in
test_extra_method_select_argument_with_dashes_and_values
[[('dashed-value', 1), ('headline', 'Article 11')], [('dashed-value',
1), ('headline', 'Article 12')]])
AssertionError: Lists differ: [[(u'dashed-value', 1L), (u'he... != [[(u
'dashed-value', 1), (u'hea...
Second list contains 1 additional elements.
First extra element 1:
[(u'dashed-value', 1), (u'headline', u'Article 12')]
- [[(u'dashed-value', 1L), (u'headline', u'Article 11')]]
? - ^
+ [[(u'dashed-value', 1), (u'headline', u'Article 11')],
? ^
+ [(u'dashed-value', 1), (u'headline', u'Article 12')]]
======================================================================
FAIL: test_year_lookup_edge_case (basic.tests.ModelTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/jon/devel/django/tests/basic/tests.py", line 236, in
test_year_lookup_edge_case
["<Article: Article 11>", "<Article: Article 12>"])
File "/home/jon/devel/django/django/test/testcases.py", line 901, in
assertQuerysetEqual
return self.assertEqual(list(items), values, msg=msg)
AssertionError: Lists differ: ['<Article: Article 11>'] != [u'<Article:
Article 11>', u'<...
Second list contains 1 additional elements.
First extra element 1:
<Article: Article 12>
- ['<Article: Article 11>']
+ [u'<Article: Article 11>', u'<Article: Article 12>']
----------------------------------------------------------------------
}}}
PR to follow.
--
Ticket URL: <https://code.djangoproject.com/ticket/24584>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* has_patch: 0 => 1
* needs_tests: => 0
* needs_docs: => 0
Comment:
https://github.com/django/django/pull/4453
--
Ticket URL: <https://code.djangoproject.com/ticket/24584#comment:1>
Comment (by claudep):
Can you look at [9e746c13e81241fbf1ae64ec118edaa491790046] and see if
partially reverting that patch (stripping microseconds based on
`connection.features.supports_microsecond_precision`) does the job?
If we could prevent touching to `get_prep_value`, it would be better.
--
Ticket URL: <https://code.djangoproject.com/ticket/24584#comment:2>
Comment (by jdufresne):
Thanks!
I have updated the patch based on your suggestion.
--
Ticket URL: <https://code.djangoproject.com/ticket/24584#comment:3>
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/24584#comment:4>
* stage: Accepted => Ready for checkin
Comment:
Thanks Jon, the patch looks good!
Tim, are you OK for backporting (considering current test failures with
this specific MySQL/MySQLdb combination)?
--
Ticket URL: <https://code.djangoproject.com/ticket/24584#comment:5>
Comment (by timgraham):
Yes, backport is fine with me. Let's add release notes, of course.
--
Ticket URL: <https://code.djangoproject.com/ticket/24584#comment:6>
Comment (by jdufresne):
Release notes added to PR. Thanks.
--
Ticket URL: <https://code.djangoproject.com/ticket/24584#comment:7>
* status: new => closed
* resolution: => fixed
Comment:
In [changeset:"2cf58e80d1be46ae95f77c95fe014921742295dd" 2cf58e8]:
{{{
#!CommitTicketReference repository=""
revision="2cf58e80d1be46ae95f77c95fe014921742295dd"
Fixed #24584 -- Fixed microsecond handling with older MySQLdb
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/24584#comment:8>
Comment (by Claude Paroz <claude@…>):
In [changeset:"551d4bb46a3db7afed2d9bab4b27628a0a44b0fc" 551d4bb4]:
{{{
#!CommitTicketReference repository=""
revision="551d4bb46a3db7afed2d9bab4b27628a0a44b0fc"
[1.8.x] Fixed #24584 -- Fixed microsecond handling with older MySQLdb
Backport of 2cf58e80d from master.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/24584#comment:9>