]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
[sqlite] Fix reflection of constraints in attached schemas 8867/head
authorMichael Gorven <michael@gorven.net>
Wed, 23 Nov 2022 23:13:32 +0000 (15:13 -0800)
committerMichael Gorven <michael@gorven.net>
Wed, 23 Nov 2022 23:48:55 +0000 (15:48 -0800)
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
test/dialect/test_sqlite.py

index 0959d0417cf68a6a78207feac26485d832e92ba5..612d8f9063257722f622d692f772499eb7fb6af6 100644 (file)
@@ -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:
index ff98fea149b8669ad9bd64c985d62bc9d2d25c87..1f7a06dffb5c7995f66ee6667920dceccedec4df 100644 (file)
@@ -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)