]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
fix sqlalchemy#10777
authorEllis Valentiner <ellisvalentiner@gmail.com>
Tue, 19 Dec 2023 15:07:34 +0000 (10:07 -0500)
committerEllis Valentiner <ellisvalentiner@gmail.com>
Tue, 19 Dec 2023 15:07:34 +0000 (10:07 -0500)
lib/sqlalchemy/dialects/postgresql/base.py
test/dialect/postgresql/test_reflection.py

index ea7ac156fe1b26cacb6d84e33a126a1938fc779a..f692377dba0034197df530c003f0b03534932ac3 100644 (file)
@@ -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)
index ab4fa2c038d78a57e04c0e9e8f3c7f5317dbf4dc..615b51e518549123533517fca8325889f3e3fb90 100644 (file)
@@ -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(