]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Allow Table._reset_exported to silently pass
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 24 Jul 2016 21:37:25 +0000 (17:37 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 24 Jul 2016 21:41:14 +0000 (17:41 -0400)
Fixed bug in :class:`.Table` where the internal method
``_reset_exported()`` would corrupt the state of the object.  This
method is intended for selectable objects and is called by the ORM
in some cases; an erroneous mapper configuration would could lead the
ORM to call this on on a :class:`.Table` object.

Change-Id: I63fa34ee0cdf16358bb125c556390df79758bcbc
Fixes: #3755
(cherry picked from commit 149fb5f55a5df3f31f6575919a5a5a2e5ba9cb0c)

doc/build/changelog/changelog_10.rst
lib/sqlalchemy/orm/mapper.py
lib/sqlalchemy/sql/schema.py
test/sql/test_metadata.py

index c977c7366d0e67d9d28375cc5d8f179406717d60..16a38e662632fb4ce95b1271a614d7bddad47366 100644 (file)
 .. changelog::
     :version: 1.0.15
 
+    .. change::
+        :tags: bug, sql
+        :tickets: 3755
+
+        Fixed bug in :class:`.Table` where the internal method
+        ``_reset_exported()`` would corrupt the state of the object.  This
+        method is intended for selectable objects and is called by the ORM
+        in some cases; an erroneous mapper configuration would could lead the
+        ORM to call this on on a :class:`.Table` object.
+
     .. change::
         :tags: bug, ext
         :tickets: 3743
index 2a1b9e6190aa836c4c3bc97de9ed81df36e50ebc..534e5e451abdbb4de7aa1f6fb9c47b2557239e8d 100644 (file)
@@ -1180,7 +1180,6 @@ class Mapper(InspectionAttr):
             instrumentation.unregister_class(self.class_)
 
     def _configure_pks(self):
-
         self.tables = sql_util.find_tables(self.mapped_table)
 
         self._pks_by_table = {}
@@ -1266,7 +1265,6 @@ class Mapper(InspectionAttr):
                 col.table not in self._cols_by_table))
 
     def _configure_properties(self):
-
         # Column and other ClauseElement objects which are mapped
         self.columns = self.c = util.OrderedProperties()
 
index f9c6d05a91e934d6faa382f6c2ffc26ba1186614..25f13113c8a70625cec284e1aebb3ba09473ed6e 100644 (file)
@@ -598,6 +598,9 @@ class Table(DialectKWArgs, SchemaItem, TableClause):
     def _init_collections(self):
         pass
 
+    def _reset_exported(self):
+        pass
+
     @util.memoized_property
     def _autoincrement_column(self):
         for col in self.primary_key:
index d3c2325d773ff78ff18759545370d8fa94b6823d..1849fbef787b7ce6cf6e5c3eebe680b0413dbc75 100644 (file)
@@ -1229,6 +1229,21 @@ class TableTest(fixtures.TestBase, AssertsCompiledSQL):
             t.info['bar'] = 'zip'
             assert t.info['bar'] == 'zip'
 
+    def test_reset_exported_passes(self):
+
+        m = MetaData()
+
+        t = Table('t', m, Column('foo', Integer))
+        eq_(
+            list(t.c), [t.c.foo]
+        )
+
+        t._reset_exported()
+
+        eq_(
+            list(t.c), [t.c.foo]
+        )
+
     def test_foreign_key_constraints_collection(self):
         metadata = MetaData()
         t1 = Table('foo', metadata, Column('a', Integer))