]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Fixed bug whereby using :meth:`.MetaData.reflect` across a remote
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 3 Jun 2013 20:40:59 +0000 (16:40 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 3 Jun 2013 20:40:59 +0000 (16:40 -0400)
schema as well as a local schema could produce wrong results
in the case where both schemas had a table of the same name.
[ticket:2728]

doc/build/changelog/changelog_08.rst
doc/build/changelog/changelog_09.rst
lib/sqlalchemy/schema.py
test/engine/test_reflection.py

index 7e8e618a4e83a39994f7aacdff742c8ed8173d67..ed633ec6768f4557241087a9ef17595ce5813226 100644 (file)
@@ -6,6 +6,14 @@
 .. changelog::
     :version: 0.8.2
 
+    .. change::
+        :tags: bug, sql, reflection
+        :tickets: 2728
+
+        Fixed bug whereby using :meth:`.MetaData.reflect` across a remote
+        schema as well as a local schema could produce wrong results
+        in the case where both schemas had a table of the same name.
+
     .. change::
         :tags: bug, sql
         :tickets: 2726
index 3c96821053820e951e1d0f5137f20306b79aafe8..08a7e74890e594d0c62710bfa06ca61ff2c1fb57 100644 (file)
@@ -6,6 +6,15 @@
 .. changelog::
     :version: 0.9.0
 
+    .. change::
+        :tags: bug, sql, reflection
+        :tickets: 2728
+
+        Fixed bug whereby using :meth:`.MetaData.reflect` across a remote
+        schema as well as a local schema could produce wrong results
+        in the case where both schemas had a table of the same name.
+        Also in 0.8.2.
+
     .. change::
         :tags: bug, sql
         :tickets: 2726
index 3a74cbd59dc221013b707038e4a0bcd406aab68c..3d59e82910dcf8c85f8890570e598f2d62f85ccd 100644 (file)
@@ -2711,13 +2711,22 @@ class MetaData(SchemaItem):
                     bind.dialect.get_view_names(conn, schema)
                 )
 
+            if schema is not None:
+                available_w_schema = util.OrderedSet(["%s.%s" % (schema, name)
+                                        for name in available])
+            else:
+                available_w_schema = available
+
             current = set(self.tables)
 
             if only is None:
-                load = [name for name in available if name not in current]
+                load = [name for name, schname in
+                            zip(available, available_w_schema)
+                            if schname not in current]
             elif util.callable(only):
-                load = [name for name in available
-                    if name not in current and only(name, self)]
+                load = [name for name, schname in
+                            zip(available, available_w_schema)
+                            if schname not in current and only(name, self)]
             else:
                 missing = [name for name in only if name not in available]
                 if missing:
index a562ef73b5c2ead9c289b85016e6314159d2d0a6..eefa6872846bcdac5ca64ad59dfca32868226dd7 100644 (file)
@@ -1245,6 +1245,30 @@ class SchemaTest(fixtures.TestBase):
                 'test_schema.email_addresses'])
         )
 
+    @testing.requires.schemas
+    @testing.provide_metadata
+    def test_reflect_all_schemas_default_overlap(self):
+        t1 = Table('t', self.metadata,
+                Column('id', Integer, primary_key=True))
+
+        t2 = Table('t', self.metadata,
+            Column('id1', sa.ForeignKey('t.id')),
+            schema="test_schema"
+        )
+
+        self.metadata.create_all()
+        m2 = MetaData()
+        m2.reflect(testing.db, schema="test_schema")
+
+        m3 = MetaData()
+        m3.reflect(testing.db)
+        m3.reflect(testing.db, schema="test_schema")
+
+        eq_(
+            set((t.name, t.schema) for t in m2.tables.values()),
+            set((t.name, t.schema) for t in m3.tables.values())
+        )
+