]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Fix reflection of constraints in attached schemas
authorMichael Gorven <michael@gorven.net>
Thu, 24 Nov 2022 08:47:26 +0000 (03:47 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 24 Nov 2022 15:18:11 +0000 (10:18 -0500)
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

doc/build/changelog/unreleased_14/8866.rst [new file with mode: 0644]
lib/sqlalchemy/dialects/sqlite/base.py
test/dialect/test_sqlite.py

diff --git a/doc/build/changelog/unreleased_14/8866.rst b/doc/build/changelog/unreleased_14/8866.rst
new file mode 100644 (file)
index 0000000..0b82e8d
--- /dev/null
@@ -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.
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)