]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
reverse constraint option ordering 10778/head
authorEllis Valentiner <ellisvalentiner@gmail.com>
Wed, 20 Dec 2023 14:34:40 +0000 (09:34 -0500)
committerEllis Valentiner <ellisvalentiner@gmail.com>
Wed, 20 Dec 2023 14:34:40 +0000 (09:34 -0500)
lib/sqlalchemy/dialects/postgresql/base.py
test/dialect/postgresql/test_reflection.py

index f692377dba0034197df530c003f0b03534932ac3..6216ad980149525d1d179d05e1c45402a8c946f3 100644 (file)
@@ -4697,9 +4697,10 @@ class PGDialect(default.DefaultDialect):
             # "CHECK (some_boolean_function(a))"
             # "CHECK (((a\n < 1)\n OR\n (a\n >= 5))\n)"
             # "CHECK (a NOT NULL) NO INHERIT"
+            # "CHECK (a NOT NULL) NO INHERIT NOT VALID"
 
             m = re.match(
-                r"^CHECK *\((.+)\)( NOT VALID)?( NO INHERIT)?$", src, flags=re.DOTALL
+                r"^CHECK *\((.+)\)( NO INHERIT)?( NOT VALID)?$", src, flags=re.DOTALL
             )
             if not m:
                 util.warn("Could not parse CHECK constraint text: %r" % src)
@@ -4713,7 +4714,7 @@ class PGDialect(default.DefaultDialect):
                 "sqltext": sqltext,
                 "comment": comment,
             }
-            if m and m.group(2):
+            if m and " NOT VALID" in m.groups():
                 entry["dialect_options"] = {"not_valid": True}
 
             check_constraints[(schema, table_name)].append(entry)
index 615b51e518549123533517fca8325889f3e3fb90..4bb635c1c24deadf796954fc7e0e95c3bfa45407 100644 (file)
@@ -2199,7 +2199,8 @@ class ReflectionTest(
 
     def test_reflect_with_no_inherit_check_constraint(self):
         rows = [
-            ("foo", "some name", "CHECK ((a IS NOT NULL)) NO INHERIT", None)
+            ("foo", "some name", "CHECK ((a IS NOT NULL)) NO INHERIT", None),
+            ("foo", "some name", "CHECK ((a IS NOT NULL)) NO INHERIT NOT VALID", None),
         ]
         conn = mock.Mock(
             execute=lambda *arg, **kw: mock.MagicMock(
@@ -2215,9 +2216,14 @@ class ReflectionTest(
                 {
                     "name": "some name",
                     "sqltext": "a IS NOT NULL",
-                    "dialect_options": {"no_inherit": True},
                     "comment": None,
-                }
+                },
+                {
+                    "name": "some name",
+                    "sqltext": "a IS NOT NULL",
+                    "dialect_options": {"not_valid": True},
+                    "comment": None,
+                },
             ],
         )