From 94a5736170f5c944d3dad1ef91dc8550c72a4dc5 Mon Sep 17 00:00:00 2001 From: Michael Gorven Date: Wed, 23 Nov 2022 15:13:32 -0800 Subject: [PATCH] [sqlite] Fix reflection of constraints in attached schemas The `index_info` pragma wasn't specifying the schema, which resulted in column names not being detected for unique constraints in other schemas. Fixes: #8866 --- lib/sqlalchemy/dialects/sqlite/base.py | 2 +- test/dialect/test_sqlite.py | 24 +++++++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/lib/sqlalchemy/dialects/sqlite/base.py b/lib/sqlalchemy/dialects/sqlite/base.py index 0959d0417c..612d8f9063 100644 --- a/lib/sqlalchemy/dialects/sqlite/base.py +++ b/lib/sqlalchemy/dialects/sqlite/base.py @@ -2487,7 +2487,7 @@ class SQLiteDialect(default.DefaultDialect): # loop thru unique indexes to get the column names. for idx in list(indexes): pragma_index = self._get_table_pragma( - connection, "index_info", idx["name"] + connection, "index_info", idx["name"], schema=schema ) for row in pragma_index: diff --git a/test/dialect/test_sqlite.py b/test/dialect/test_sqlite.py index ff98fea149..1f7a06dffb 100644 --- a/test/dialect/test_sqlite.py +++ b/test/dialect/test_sqlite.py @@ -827,7 +827,7 @@ class AttachedDBTest(fixtures.TestBase): Table( "another_created", meta, - Column("bat", Integer), + Column("bat", Integer, unique=True), Column("hoho", String), schema="test_schema", ) @@ -909,6 +909,28 @@ class AttachedDBTest(fixtures.TestBase): {"created", "another_created"}, ) + def test_unique_constraints(self): + self._fixture() + insp = inspect(self.conn) + eq_( + [ + d["column_names"] + for d in insp.get_unique_constraints( + "created", schema="test_schema" + ) + ], + [], + ) + eq_( + [ + d["column_names"] + for d in insp.get_unique_constraints( + "another_created", schema="test_schema" + ) + ], + [["bat"]], + ) + def test_schema_names(self): self._fixture() insp = inspect(self.conn) -- 2.47.3