From: Michael Gorven Date: Thu, 24 Nov 2022 08:47:26 +0000 (-0500) Subject: Fix reflection of constraints in attached schemas X-Git-Tag: rel_1_4_45~25 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7a0a76271793ffc3ded684a98927fe84258b9500;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Fix reflection of constraints in attached schemas Backported a fix for SQLite reflection of unique constraints in attached schemas, released in 2.0 as a small part of :ticket:`4379`. Previously, unique constraints in attached schemas would be ignored by SQLite reflection. Pull request courtesy Michael Gorven. Fixes: #8866 Closes: #8867 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/8867 Pull-request-sha: 94a5736170f5c944d3dad1ef91dc8550c72a4dc5 Change-Id: Id414aeed9d6ce58877d81df2459f6d4f308750a8 --- diff --git a/doc/build/changelog/unreleased_14/8866.rst b/doc/build/changelog/unreleased_14/8866.rst new file mode 100644 index 0000000000..0b82e8d303 --- /dev/null +++ b/doc/build/changelog/unreleased_14/8866.rst @@ -0,0 +1,8 @@ +.. change:: + :tags: bug, sqlite + :tickets: 8866 + + Backported a fix for SQLite reflection of unique constraints in attached + schemas, released in 2.0 as a small part of :ticket:`4379`. Previously, + unique constraints in attached schemas would be ignored by SQLite + reflection. Pull request courtesy Michael Gorven. 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)