summaryrefslogtreecommitdiff
path: root/django/db
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2019-07-20 15:38:43 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2019-12-04 18:22:08 +0100
commitc06492dd87342b5102db44f0d50fa0bb01cbb743 (patch)
tree25c8ba9910ed0851b4efd6bb81fb298adef420a2 /django/db
parentad88524e4db91dc2f148cf40184a81a454ee7aac (diff)
Fixed #23524 -- Allowed DATABASES['TIME_ZONE'] option on PostgreSQL.
Diffstat (limited to 'django/db')
-rw-r--r--django/db/backends/base/base.py20
-rw-r--r--django/db/backends/postgresql/base.py6
-rw-r--r--django/db/backends/postgresql/utils.py7
3 files changed, 12 insertions, 21 deletions
diff --git a/django/db/backends/base/base.py b/django/db/backends/base/base.py
index 08d5f755aa..61e0dc0ca0 100644
--- a/django/db/backends/base/base.py
+++ b/django/db/backends/base/base.py
@@ -124,11 +124,11 @@ class BaseDatabaseWrapper:
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.
+ Other users connecting to the database can choose their own time zone.
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.
+ Django uses may be constrained by the requirements of other users of
+ the database.
"""
if not settings.USE_TZ:
return None
@@ -205,15 +205,11 @@ class BaseDatabaseWrapper:
self.run_on_commit = []
def check_settings(self):
- if self.settings_dict['TIME_ZONE'] is not None:
- if not settings.USE_TZ:
- raise ImproperlyConfigured(
- "Connection '%s' cannot set TIME_ZONE because USE_TZ is "
- "False." % self.alias)
- elif self.features.supports_timezones:
- raise ImproperlyConfigured(
- "Connection '%s' cannot set TIME_ZONE because its engine "
- "handles time zones conversions natively." % self.alias)
+ if self.settings_dict['TIME_ZONE'] is not None and not settings.USE_TZ:
+ raise ImproperlyConfigured(
+ "Connection '%s' cannot set TIME_ZONE because USE_TZ is False."
+ % self.alias
+ )
@async_unsafe
def ensure_connection(self):
diff --git a/django/db/backends/postgresql/base.py b/django/db/backends/postgresql/base.py
index bf15a13018..0ab81ced74 100644
--- a/django/db/backends/postgresql/base.py
+++ b/django/db/backends/postgresql/base.py
@@ -47,7 +47,6 @@ from .features import DatabaseFeatures # NOQA isort:skip
from .introspection import DatabaseIntrospection # NOQA isort:skip
from .operations import DatabaseOperations # NOQA isort:skip
from .schema import DatabaseSchemaEditor # NOQA isort:skip
-from .utils import utc_tzinfo_factory # NOQA isort:skip
psycopg2.extensions.register_adapter(SafeString, psycopg2.extensions.QuotedString)
psycopg2.extras.register_uuid()
@@ -231,9 +230,12 @@ class DatabaseWrapper(BaseDatabaseWrapper):
cursor = self.connection.cursor(name, scrollable=False, withhold=self.connection.autocommit)
else:
cursor = self.connection.cursor()
- cursor.tzinfo_factory = utc_tzinfo_factory if settings.USE_TZ else None
+ cursor.tzinfo_factory = self.tzinfo_factory if settings.USE_TZ else None
return cursor
+ def tzinfo_factory(self, offset):
+ return self.timezone
+
@async_unsafe
def chunked_cursor(self):
self._named_cursor_idx += 1
diff --git a/django/db/backends/postgresql/utils.py b/django/db/backends/postgresql/utils.py
deleted file mode 100644
index 2c03ab36cd..0000000000
--- a/django/db/backends/postgresql/utils.py
+++ /dev/null
@@ -1,7 +0,0 @@
-from django.utils.timezone import utc
-
-
-def utc_tzinfo_factory(offset):
- if offset != 0:
- raise AssertionError("database connection isn't set to UTC")
- return utc