From ad88524e4db91dc2f148cf40184a81a454ee7aac Mon Sep 17 00:00:00 2001 From: Aymeric Augustin Date: Sat, 20 Jul 2019 18:31:47 +0200 Subject: [PATCH] Refs #23524 -- Unified BaseDatabaseWrapper.timezone. There was a special case in this property to return None when the database backend supports time zone. However, only the PostgreSQL backend supports time zones and it never uses this property. --- django/db/backends/base/base.py | 17 ++++++++++------- docs/releases/3.1.txt | 5 +++++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/django/db/backends/base/base.py b/django/db/backends/base/base.py index 9a4c27f0f33..08d5f755aae 100644 --- a/django/db/backends/base/base.py +++ b/django/db/backends/base/base.py @@ -117,18 +117,21 @@ class BaseDatabaseWrapper: @cached_property def timezone(self): """ - Time zone for datetimes stored as naive values in the database. + Return a tzinfo of the database connection time zone. - Return a tzinfo object or None. + This is only used when time zone support is enabled. When a datetime is + read from the database, it is always returned in this time zone. - This is only needed when time zone support is enabled and the database - doesn't support time zones. (When the database supports time zones, - the adapter handles aware datetimes so Django doesn't need to.) + When the database backend supports time zones, it doesn't matter which + time zone Django uses, as long as aware datetimes are used everywhere. + For simplicity, Django selects UTC. + + When the database backend doesn't support time zones, the time zone + Django uses can be selected with the TIME_ZONE configuration option, so + it can match what other users of the database expect. """ if not settings.USE_TZ: return None - elif self.features.supports_timezones: - return None elif self.settings_dict['TIME_ZONE'] is None: return timezone.utc else: diff --git a/docs/releases/3.1.txt b/docs/releases/3.1.txt index b4179883ab1..58f14e172d9 100644 --- a/docs/releases/3.1.txt +++ b/docs/releases/3.1.txt @@ -297,6 +297,11 @@ backends. * ``DatabaseOperations.fetch_returned_insert_columns()`` now requires an additional ``returning_params`` argument. +* ``connection.timezone`` property is now ``'UTC'`` by default, or the + :setting:`TIME_ZONE ` when :setting:`USE_TZ` is ``True`` + on databases that support time zones. Previously, it was ``None`` on + databases that support time zones. + Dropped support for MariaDB 10.1 --------------------------------