Fixed #17882 -- Reopened the database connection when a test changes time zone settings. Thanks brodie for the report.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17699 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
f7daa38a00
commit
aa900c39a8
|
@ -1,5 +1,14 @@
|
||||||
|
from django.conf import settings
|
||||||
|
from django.db import close_connection
|
||||||
from django.dispatch import Signal
|
from django.dispatch import Signal
|
||||||
|
|
||||||
template_rendered = Signal(providing_args=["template", "context"])
|
template_rendered = Signal(providing_args=["template", "context"])
|
||||||
|
|
||||||
setting_changed = Signal(providing_args=["setting", "value"])
|
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)
|
||||||
|
|
|
@ -63,8 +63,6 @@ class BaseDateTimeTests(TestCase):
|
||||||
self._old_tz = os.environ.get('TZ')
|
self._old_tz = os.environ.get('TZ')
|
||||||
os.environ['TZ'] = 'Africa/Nairobi'
|
os.environ['TZ'] = 'Africa/Nairobi'
|
||||||
time.tzset()
|
time.tzset()
|
||||||
# Create a new cursor, for test cases that change the value of USE_TZ.
|
|
||||||
connection.close()
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def tearDownClass(self):
|
def tearDownClass(self):
|
||||||
|
|
Loading…
Reference in New Issue