]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Join by space instead of empty string, trim the match as well
authorEric Borczuk <eric@trialspark.com>
Thu, 27 Feb 2020 17:40:14 +0000 (12:40 -0500)
committerEric Borczuk <eric@trialspark.com>
Thu, 27 Feb 2020 17:40:14 +0000 (12:40 -0500)
lib/sqlalchemy/dialects/postgresql/base.py
test/dialect/postgresql/test_reflection.py

index 0b8d6f197b11655e42d6440700749837205ef2cd..11b8714a1e9cd849ec319681c7070c55583379de 100644 (file)
@@ -3495,7 +3495,7 @@ class PGDialect(default.DefaultDialect):
                 util.warn("Could not parse CHECK constraint text: %r" % src)
                 sqltext = ""
             else:
-                match_without_newlines = ''.join(m.group(1).splitlines())
+                match_without_newlines = ' '.join(m.group(1).splitlines()).strip()
                 sqltext = re.sub(r"^\((.+)\)$", r"\1", match_without_newlines)
             entry = {"name": name, "sqltext": sqltext}
             if m and m.group(2):
index 092363e03868a25e24b2646707a6108784c62113..8438ede0bdb7ffb7be21f5fb7023d32c609e9fb6 100644 (file)
@@ -1583,7 +1583,11 @@ class ReflectionTest(fixtures.TestBase):
                 testing.db.dialect.get_check_constraints(conn, "foo")
 
     def test_reflect_extra_newlines(self):
-        rows = [("some name", "CHECK (\n(a \nIS\n NOT\n\n NULL\n)\n)")]
+        rows = [
+            ("some name", "CHECK (\n(a \nIS\n NOT\n\n NULL\n)\n)"),
+            ("some other name", "CHECK ((b\nIS\nNOT\nNULL))"),
+            ("some CRLF name", "CHECK ((c\r\n\r\nIS\r\nNOT\r\nNULL))"),
+        ]
         conn = mock.Mock(
             execute=lambda *arg, **kw: mock.MagicMock(
                 fetchall=lambda: rows, __iter__=lambda self: iter(rows)
@@ -1600,7 +1604,15 @@ class ReflectionTest(fixtures.TestBase):
                 [
                     {
                         "name": "some name",
-                        "sqltext": "a IS NOT NULL",
+                        "sqltext": "a  IS  NOT   NULL ",
+                    },
+                    {
+                        "name": "some other name",
+                        "sqltext": "b IS NOT NULL",
+                    },
+                    {
+                        "name": "some CRLF name",
+                        "sqltext": "c  IS NOT NULL",
                     }
                 ],
             )