summaryrefslogtreecommitdiff
path: root/django/test
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2012-03-13 23:29:15 +0000
committerAymeric Augustin <aymeric.augustin@m4x.org>2012-03-13 23:29:15 +0000
commit3ef55dfaa03b3f5be3ee3632dfc59b8f752d2dec (patch)
tree8124c0dd366ed0c007f3dc0631a761709aa535a6 /django/test
parent4b14546215ad4ef15f04e748e3b5f0da7b613b45 (diff)
Fixed #17882 (again) -- Updated the database connections' time zone when time-zone-related settings are changed in tests.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17709 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/test')
-rw-r--r--django/test/signals.py23
1 files changed, 16 insertions, 7 deletions
diff --git a/django/test/signals.py b/django/test/signals.py
index d6797395cf..01d55817a2 100644
--- a/django/test/signals.py
+++ b/django/test/signals.py
@@ -1,14 +1,23 @@
from django.conf import settings
-from django.db import close_connection
+from django.db import connections
from django.dispatch import Signal
template_rendered = Signal(providing_args=["template", "context"])
setting_changed = Signal(providing_args=["setting", "value"])
-# Close the database connection to re-establish it with the proper time zone.
-def close_connection_on_time_zone_change(**kwargs):
- if (kwargs['setting'] == 'USE_TZ'
- or (kwargs['setting'] == 'TIME_ZONE' and not settings.USE_TZ)):
- close_connection()
-setting_changed.connect(close_connection_on_time_zone_change)
+def update_connections_time_zone(**kwargs):
+ if kwargs['setting'] == 'USE_TZ' and settings.TIME_ZONE != 'UTC':
+ USE_TZ, TIME_ZONE = kwargs['value'], settings.TIME_ZONE
+ elif kwargs['setting'] == 'TIME_ZONE' and not settings.USE_TZ:
+ USE_TZ, TIME_ZONE = settings.USE_TZ, kwargs['value']
+ else: # no need to change the database connnections' time zones
+ return
+
+ tz = 'UTC' if USE_TZ else TIME_ZONE
+ for conn in connections.all():
+ tz_sql = conn.ops.set_time_zone_sql()
+ if tz_sql:
+ conn.cursor().execute(tz_sql, [tz])
+
+setting_changed.connect(update_connections_time_zone)