From: Eric Borczuk Date: Thu, 27 Feb 2020 17:40:14 +0000 (-0500) Subject: Join by space instead of empty string, trim the match as well X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6d80171c31d7c4fcd24c2ed4acf2c91ad2af3a24;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Join by space instead of empty string, trim the match as well --- diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index 0b8d6f197b..11b8714a1e 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -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): diff --git a/test/dialect/postgresql/test_reflection.py b/test/dialect/postgresql/test_reflection.py index 092363e038..8438ede0bd 100644 --- a/test/dialect/postgresql/test_reflection.py +++ b/test/dialect/postgresql/test_reflection.py @@ -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", } ], )