]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Fixed reflected SQLite check constraint name extraction regex.
authorJeff Horemans <jeff.horemans@vortex-financials.be>
Wed, 7 Aug 2024 11:18:42 +0000 (13:18 +0200)
committerJeff Horemans <jeff.horemans@vortex-financials.be>
Wed, 7 Aug 2024 11:18:42 +0000 (13:18 +0200)
lib/sqlalchemy/dialects/sqlite/base.py
test/dialect/test_sqlite.py

index 25f8631b21f12c781273467ada8f3b4cdb7a2997..545f320f6111110ca01e76f5b45b3c1229803364 100644 (file)
@@ -2624,7 +2624,7 @@ class SQLiteDialect(default.DefaultDialect):
             connection, table_name, schema=schema, **kw
         )
 
-        CHECK_PATTERN = r"(?:CONSTRAINT (.+) +)?CHECK *\( *((.|\n)+?) *\)(?:, ?\n|\n) *"
+        CHECK_PATTERN = r"(?:CONSTRAINT ([^\s]+) +)?CHECK *\( *(.+?) *\)(?:, ?\n|\n) *"
         cks = []
         # NOTE: we aren't using re.S here because we actually are
         # taking advantage of each CHECK constraint being all on one
index 10a2736c02901a80eaf873846cf5bea2abe5b686..4014eeff5debc932eb9fa74240ac40424133409b 100644 (file)
@@ -1818,7 +1818,9 @@ class ConstraintReflectionTest(fixtures.TestBase):
 
             # intentional new line
             Table("r", meta, Column("id", Integer), Column("value", Integer), PrimaryKeyConstraint("id"),
-                  CheckConstraint("((value > 0) AND \n(value < 100))"), CheckConstraint("id > 0"))
+                  CheckConstraint("id > 0"),
+                  CheckConstraint("((value > 0) AND \n\t(value < 100))", name='ck_r_value'),
+            )
 
             meta.create_all(conn)
 
@@ -2514,8 +2516,10 @@ class ConstraintReflectionTest(fixtures.TestBase):
     def test_multiline_check_constraints(self):
         inspector = inspect(testing.db)
         constraints = inspector.get_check_constraints('r')
-        eq_(constraints[0]['sqltext'], "((value > 0) AND \n(value < 100))")
+        eq_(constraints[1]['name'], None)
         eq_(constraints[1]['sqltext'], "id > 0")
+        eq_(constraints[0]['name'], "ck_r_value")
+        eq_(constraints[0]['sqltext'], "((value > 0) AND \n\t(value < 100))")
 
 class SavepointTest(fixtures.TablesTest):
     """test that savepoints work when we use the correct event setup"""