[Django] #23820: Make it possible to override USE_TZ & TIME_ZONE on a per-database basis

32 views
Skip to first unread message

Django

unread,
Nov 14, 2014, 9:08:51 AM11/14/14
to django-...@googlegroups.com
#23820: Make it possible to override USE_TZ & TIME_ZONE on a per-database basis
-------------------------------------+-------------------------------------
Reporter: aaugustin | Owner: nobody
Type: New | Status: new
feature | Version: master
Component: Database | Keywords:
layer (models, ORM) | Has patch: 0
Severity: Normal | Needs tests: 0
Triage Stage: | Easy pickings: 0
Unreviewed |
Needs documentation: 0 |
Patch needs improvement: 0 |
UI/UX: 0 |
-------------------------------------+-------------------------------------
When integrating with a legacy database, datetimes are most often encoded
in local time. This doesn't work well with projects where `USE_TZ = True`.

The configuration for each database backend should accept a `TIME_ZONE`
option to enforce interpretation of datetimes stored in that database as
naive values in that time zone.

Setting this option when `USE_TZ = False` could either be an error or
perform a conversion to the global default `TIME_ZONE`. The latter may be
too complicated to be worth the effort.

--
Ticket URL: <https://code.djangoproject.com/ticket/23820>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Nov 14, 2014, 9:52:48 AM11/14/14
to django-...@googlegroups.com
#23820: Make it possible to override USE_TZ & TIME_ZONE on a per-database basis
-------------------------------------+-------------------------------------
Reporter: aaugustin | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version: master
(models, ORM) | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by timgraham):

* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/23820#comment:1>

Django

unread,
Apr 12, 2015, 8:23:50 AM4/12/15
to django-...@googlegroups.com
#23820: Make it possible to override USE_TZ & TIME_ZONE on a per-database basis
-------------------------------------+-------------------------------------
Reporter: aaugustin | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by aaugustin):

At least for SQLite, this will require getting rid of the
[https://docs.python.org/3/library/sqlite3.html#sqlite3.register_converter
global converters] as there is no way to register converters per
connection.

I'll try to replace the converters, which are quite messy anyway, with an
implementation of `DateTimeField.from_db_value`.

--
Ticket URL: <https://code.djangoproject.com/ticket/23820#comment:2>

Django

unread,
Apr 12, 2015, 8:38:03 AM4/12/15
to django-...@googlegroups.com
#23820: Make it possible to override USE_TZ & TIME_ZONE on a per-database basis
-------------------------------------+-------------------------------------
Reporter: aaugustin | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by aaugustin):

`DatabaseOperations.convert_datetimefield_value` seems to be a better
match for what I'm trying to achieve.

--
Ticket URL: <https://code.djangoproject.com/ticket/23820#comment:3>

Django

unread,
Apr 13, 2015, 2:09:16 PM4/13/15
to django-...@googlegroups.com
#23820: Make it possible to override USE_TZ & TIME_ZONE on a per-database basis
-------------------------------------+-------------------------------------
Reporter: aaugustin | Owner: aaugustin
Type: New feature | Status: assigned

Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by aaugustin):

* status: new => assigned
* owner: nobody => aaugustin


--
Ticket URL: <https://code.djangoproject.com/ticket/23820#comment:4>

Django

unread,
Apr 13, 2015, 2:17:19 PM4/13/15
to django-...@googlegroups.com
#23820: Make it possible to override USE_TZ & TIME_ZONE on a per-database basis
-------------------------------------+-------------------------------------
Reporter: aaugustin | Owner: aaugustin
Type: New feature | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by aaugustin):

This will required getting rid of the global converters and adapters for
datetimes, because they're hardcoded to use UTC regardless of the database
connection being used.

Proposal: https://groups.google.com/d/msg/django-
developers/Ci_cs0KTagM/DchJIB8-vRsJ

--
Ticket URL: <https://code.djangoproject.com/ticket/23820#comment:5>

Django

unread,
May 3, 2015, 3:30:09 PM5/3/15
to django-...@googlegroups.com
#23820: Make it possible to override USE_TZ & TIME_ZONE on a per-database basis
-------------------------------------+-------------------------------------
Reporter: aaugustin | Owner: aaugustin
Type: New feature | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by aaugustin):

* has_patch: 0 => 1


Comment:

PR: https://github.com/django/django/pull/4601

--
Ticket URL: <https://code.djangoproject.com/ticket/23820#comment:6>

Django

unread,
May 15, 2015, 2:21:41 PM5/15/15
to django-...@googlegroups.com
#23820: Make it possible to override USE_TZ & TIME_ZONE on a per-database basis
-------------------------------------+-------------------------------------
Reporter: aaugustin | Owner: aaugustin
Type: New feature | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/23820#comment:7>

Django

unread,
May 17, 2015, 4:24:01 AM5/17/15
to django-...@googlegroups.com
#23820: Make it possible to override USE_TZ & TIME_ZONE on a per-database basis
-------------------------------------+-------------------------------------
Reporter: aaugustin | Owner: aaugustin
Type: New feature | Status: closed

Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Aymeric Augustin <aymeric.augustin@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"ed83881e648771d22658f21b939f66e75c499864" ed83881]:
{{{
#!CommitTicketReference repository=""
revision="ed83881e648771d22658f21b939f66e75c499864"
Fixed #23820 -- Supported per-database time zone.

The primary use case is to interact with a third-party database (not
primarily managed by Django) that doesn't support time zones and where
datetimes are stored in local time when USE_TZ is True.

Configuring a PostgreSQL database with the TIME_ZONE option while USE_TZ
is False used to result in silent data corruption. Now this is an error.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/23820#comment:10>

Django

unread,
May 17, 2015, 4:24:02 AM5/17/15
to django-...@googlegroups.com
#23820: Make it possible to override USE_TZ & TIME_ZONE on a per-database basis
-------------------------------------+-------------------------------------
Reporter: aaugustin | Owner: aaugustin
Type: New feature | Status: assigned

Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Aymeric Augustin <aymeric.augustin@…>):

In [changeset:"ec186572e6cfde4cd4bc1491ff552c5d32211d9f" ec18657]:
{{{
#!CommitTicketReference repository=""
revision="ec186572e6cfde4cd4bc1491ff552c5d32211d9f"
Removed global timezone-aware datetime converters.

Refs #23820.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/23820#comment:8>

Django

unread,
May 17, 2015, 4:24:02 AM5/17/15
to django-...@googlegroups.com
#23820: Make it possible to override USE_TZ & TIME_ZONE on a per-database basis
-------------------------------------+-------------------------------------
Reporter: aaugustin | Owner: aaugustin
Type: New feature | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Aymeric Augustin <aymeric.augustin@…>):

In [changeset:"d9521f66b1851b0eacd55bc78f801dc64123e333" d9521f6]:
{{{
#!CommitTicketReference repository=""
revision="d9521f66b1851b0eacd55bc78f801dc64123e333"
Removed global timezone-aware datetime adapters.

Refs #23820.

Fixed #19738.

Refs #17755. In order not to introduce a regression for raw queries,
parameters are passed through the connection.ops.value_to_db_* methods,
depending on their type.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/23820#comment:9>

Reply all
Reply to author
Forward
0 new messages