From f147e3ab39dd6a937ba4918d6951a16803bcd7cb Mon Sep 17 00:00:00 2001 From: Ellis Valentiner Date: Tue, 19 Dec 2023 10:07:34 -0500 Subject: [PATCH] fix sqlalchemy#10777 --- lib/sqlalchemy/dialects/postgresql/base.py | 3 ++- test/dialect/postgresql/test_reflection.py | 24 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index ea7ac156fe..f692377dba 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -4696,9 +4696,10 @@ class PGDialect(default.DefaultDialect): # "CHECK (((a > 1) AND (a < 5))) NOT VALID" # "CHECK (some_boolean_function(a))" # "CHECK (((a\n < 1)\n OR\n (a\n >= 5))\n)" + # "CHECK (a NOT NULL) NO INHERIT" m = re.match( - r"^CHECK *\((.+)\)( NOT VALID)?$", src, flags=re.DOTALL + r"^CHECK *\((.+)\)( NOT VALID)?( NO INHERIT)?$", src, flags=re.DOTALL ) if not m: util.warn("Could not parse CHECK constraint text: %r" % src) diff --git a/test/dialect/postgresql/test_reflection.py b/test/dialect/postgresql/test_reflection.py index ab4fa2c038..615b51e518 100644 --- a/test/dialect/postgresql/test_reflection.py +++ b/test/dialect/postgresql/test_reflection.py @@ -2197,6 +2197,30 @@ class ReflectionTest( ], ) + def test_reflect_with_no_inherit_check_constraint(self): + rows = [ + ("foo", "some name", "CHECK ((a IS NOT NULL)) NO INHERIT", None) + ] + conn = mock.Mock( + execute=lambda *arg, **kw: mock.MagicMock( + fetchall=lambda: rows, __iter__=lambda self: iter(rows) + ) + ) + check_constraints = testing.db.dialect.get_check_constraints( + conn, "foo" + ) + eq_( + check_constraints, + [ + { + "name": "some name", + "sqltext": "a IS NOT NULL", + "dialect_options": {"no_inherit": True}, + "comment": None, + } + ], + ) + def _apply_stm(self, connection, use_map): if use_map: return connection.execution_options( -- 2.47.3