]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
fix using tzdata-compliant time zone names
authorNils Philippsen <nils@redhat.com>
Wed, 9 Aug 2017 13:34:45 +0000 (09:34 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 9 Aug 2017 13:44:05 +0000 (09:44 -0400)
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

alembic/script/base.py
docs/build/unreleased/pr69.rst [new file with mode: 0644]
tests/test_script_production.py

index d296a0f0cff68c44cdd79f5a7c8c6c73c1d68c0d..d1760e580c665ee933f14eda37d595e0ac6c56f7 100644 (file)
@@ -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 (file)
index 0000000..2ae8dd4
--- /dev/null
@@ -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.
index c5a99b8679b029eaccd167e8a3441ae55649db81..dca06ac9ff4bdc6d526c668f1e4c5902976fddc0 100644 (file)
@@ -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,