#23631 closed Bug (fixed)
Documentation: Outdated warning about DateTimeField on MySQL?
Reported by: | Kevin Christopher Henry | Owned by: | nobody |
---|---|---|---|
Component: | Documentation | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
The MySQL Database notes say:
MySQL does not have a timezone-aware column type. If an attempt is made to store a timezone-aware time or datetime to a TimeField or DateTimeField respectively, a ValueError is raised rather than truncating data.
I don't use MySQL so I can't check this, but isn't this wrong? Wasn't this fixed in 1.4 by storing timezone-aware datetimes in UTC? This note goes back to (at least) 1.3, so I'm guessing it was just never updated.
Attachments (1)
Change History (11)
comment:1 by , 10 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
comment:2 by , 10 years ago
Resolution: | invalid |
---|---|
Status: | closed → new |
But that test class has @override_settings(TIME_ZONE='Africa/Nairobi', USE_TZ=False)
. When USE_TZ = True
the code itself shows that it should work as expected, no?
by , 10 years ago
Attachment: | 23631.diff added |
---|
comment:3 by , 10 years ago
Has patch: | set |
---|---|
Triage Stage: | Unreviewed → Accepted |
Thanks, I think the attached patch should clarify the situation then?
comment:4 by , 10 years ago
I think that wording is a little confusing if you're not already familiar with the way timezone-handling works. I would say something like this:
MySQL does not have a timezone-aware column type. When
USE_TZ = True
and an attempt is made to store a timezone-awaredatetime
(ortime
) in aDateTimeField
(orTimeField
), the datetime is converted to UTC and stored without a timezone. WhenUSE_TZ = False
, though, Django chooses to raise aValueError
rather than simply discard the timezone information in the aware datetime.
Either way, though, you should include the same warning for Oracle and SQLite, since they display the same behavior (see here and here).
(Sorry, I'm not able to create an actual patch at the moment.)
comment:5 by , 10 years ago
Thanks for the research. In that case, maybe we could just remove the note since the exception that is thrown has a helpful message?
comment:6 by , 10 years ago
I think that's fine. This note predates Django's timezone support, and the timezone documentation makes pretty clear that correct usage requires a match between USE_TZ
and timezone-awareness.
Since this has been inaccurate since version 1.4, hopefully you can backport the deletion...
comment:7 by , 10 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
This behavior is still tested: https://github.com/django/django/blob/65c1a37490b1e504cb69fb09731cfda85fcd6002/tests/timezones/tests.py#L149-L153