From: Nils Philippsen Date: Wed, 9 Aug 2017 13:34:45 +0000 (-0400) Subject: fix using tzdata-compliant time zone names X-Git-Tag: rel_0_9_5~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d1a8ff99e7c7a138d7da8e4456609f2f92ceb7a9;p=thirdparty%2Fsqlalchemy%2Falembic.git fix using tzdata-compliant time zone names Previously, time zone names were capitalized indiscriminately, making it impossible to use names containing lowercase characters with Alembic. https://en.wikipedia.org/wiki/Tz_database#Names_of_time_zones Change-Id: I89288447f91e98dc106d82a1ee233f2f3de30c78 Pull-request: https://bitbucket.org/zzzeek/alembic/pull-requests/69 --- diff --git a/alembic/script/base.py b/alembic/script/base.py index d296a0f0..d1760e58 100644 --- a/alembic/script/base.py +++ b/alembic/script/base.py @@ -451,7 +451,11 @@ class ScriptDirectory(object): def _generate_create_date(self): if self.timezone is not None: - tzinfo = tz.gettz(self.timezone.upper()) + # First, assume correct capitalization + tzinfo = tz.gettz(self.timezone) + if tzinfo is None: + # Fall back to uppercase + tzinfo = tz.gettz(self.timezone.upper()) if tzinfo is None: raise util.CommandError( "Can't locate timezone: %s" % self.timezone) diff --git a/docs/build/unreleased/pr69.rst b/docs/build/unreleased/pr69.rst new file mode 100644 index 00000000..2ae8dd4d --- /dev/null +++ b/docs/build/unreleased/pr69.rst @@ -0,0 +1,10 @@ +.. change:: + :tags: bug, commands + + Fixed bug in timezone feature introduced in + :ticket:`425` when the creation + date in a revision file is calculated, to + accommodate for timezone names that contain + mixed-case characters in their name as opposed + to all uppercase. Pull request courtesy Nils + Philippsen. diff --git a/tests/test_script_production.py b/tests/test_script_production.py index c5a99b86..dca06ac9 100644 --- a/tests/test_script_production.py +++ b/tests/test_script_production.py @@ -203,6 +203,14 @@ class ScriptNamingTest(TestBase): 2012, 7, 25, 15, 8, 5, tzinfo=tz.gettz('UTC')) ) + def test_custom_tzdata_tz(self): + self._test_tz( + 'Europe/Berlin', + datetime.datetime(2012, 7, 25, 15, 8, 5), + datetime.datetime( + 2012, 7, 25, 17, 8, 5, tzinfo=tz.gettz('Europe/Berlin')) + ) + def test_default_tz(self): self._test_tz( None,