From 6805909fadece2224ae6d68e6b22e18f1637bf79 Mon Sep 17 00:00:00 2001 From: Jeff Horemans Date: Wed, 7 Aug 2024 13:18:42 +0200 Subject: [PATCH] Fixed reflected SQLite check constraint name extraction regex. --- lib/sqlalchemy/dialects/sqlite/base.py | 2 +- test/dialect/test_sqlite.py | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/sqlalchemy/dialects/sqlite/base.py b/lib/sqlalchemy/dialects/sqlite/base.py index 25f8631b21..545f320f61 100644 --- a/lib/sqlalchemy/dialects/sqlite/base.py +++ b/lib/sqlalchemy/dialects/sqlite/base.py @@ -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 diff --git a/test/dialect/test_sqlite.py b/test/dialect/test_sqlite.py index 10a2736c02..4014eeff5d 100644 --- a/test/dialect/test_sqlite.py +++ b/test/dialect/test_sqlite.py @@ -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""" -- 2.47.3