]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
- Fixed issue in PG server default comparison where model-side defaults
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 3 Sep 2015 01:52:33 +0000 (21:52 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 3 Sep 2015 01:52:33 +0000 (21:52 -0400)
configured with Python unicode literals would leak the "u" character
from a ``repr()`` into the SQL used for comparison, creating an invalid
SQL expression, as the server-side comparison feature in PG currently
repurposes the autogenerate Python rendering feature to get a quoted
version of a plain string default.
fixes #324

alembic/__init__.py
alembic/ddl/postgresql.py
docs/build/changelog.rst
tests/test_postgresql.py

index 5645f1005a06caf5ff5549dcc7e9b4a5cd490ac3..bbd3e47fc1dbf1e29f0bee3c7a099d51aac687ec 100644 (file)
@@ -1,6 +1,6 @@
 from os import path
 
-__version__ = '0.8.2'
+__version__ = '0.8.3'
 
 package_dir = path.abspath(path.dirname(__file__))
 
index 5109b11f66343e5a9d713c72fbb01943e8cc896f..39c380d137c7c18071a849fd07b9ab60307ba292 100644 (file)
@@ -47,7 +47,8 @@ class PostgresqlImpl(DefaultImpl):
                 not isinstance(inspector_column.type, Numeric):
                 # don't single quote if the column type is float/numeric,
                 # otherwise a comparison such as SELECT 5 = '5.0' will fail
-            rendered_metadata_default = "'%s'" % rendered_metadata_default
+            rendered_metadata_default = re.sub(
+                r"^u?'?|'?$", "'", rendered_metadata_default)
 
         return not self.connection.scalar(
             "SELECT %s = %s" % (
index 27006da5e93def02eb8b0b0e8ed995de71be7a0e..96fdabcee39b07f7afcc61043e5684b542aec690 100644 (file)
@@ -3,6 +3,21 @@
 Changelog
 ==========
 
+.. changelog::
+    :version: 0.8.3
+
+    .. change::
+      :tags: bug, autogenerate, postgresql
+      :tickets: 324
+
+      Fixed issue in PG server default comparison where model-side defaults
+      configured with Python unicode literals would leak the "u" character
+      from a ``repr()`` into the SQL used for comparison, creating an invalid
+      SQL expression, as the server-side comparison feature in PG currently
+      repurposes the autogenerate Python rendering feature to get a quoted
+      version of a plain string default.
+
+
 .. changelog::
     :version: 0.8.2
     :released: August 25, 2015
index 576d957aecdb6de05027f4fa1c3ff2a37ad68e41..21ba6b9e7cb78e1b8cc370cc1fd0c916533907ae 100644 (file)
@@ -331,6 +331,21 @@ class PostgresqlDefaultCompareTest(TestBase):
             diff_expected=False
         )
 
+    def test_compare_unicode_literal(self):
+        self._compare_default_roundtrip(
+            String(),
+            u'im a default'
+        )
+
+    # TOOD: will need to actually eval() the repr() and
+    # spend more effort figuring out exactly the kind of expression
+    # to use
+    def _TODO_test_compare_character_str_w_singlequote(self):
+        self._compare_default_roundtrip(
+            String(),
+            "hel''lo",
+        )
+
     def test_compare_character_str(self):
         self._compare_default_roundtrip(
             String(),