]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Fixed issue where a :class:`.MetaData` object that used a naming
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 10 Apr 2015 15:20:14 +0000 (11:20 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 10 Apr 2015 15:20:39 +0000 (11:20 -0400)
convention would not properly work with pickle.  The attribute was
skipped leading to inconsistencies and failures if the unpickled
:class:`.MetaData` object were used to base additional tables
from.
fixes #3362

(cherry picked from commit 55c26710a1f6d6c6f87a9752035bc160f93b38d0)

doc/build/changelog/changelog_09.rst
lib/sqlalchemy/sql/schema.py
test/sql/test_metadata.py

index e48585ea7d3e6e8afed38bcd9cbe5d3934f6433b..7960da626e12f32196645517cc2e787a3d06ef9e 100644 (file)
 .. changelog::
     :version: 0.9.10
 
+    .. change::
+        :tags: bug, sql
+        :tickets: 3362
+        :versions: 1.0.0
+
+        Fixed issue where a :class:`.MetaData` object that used a naming
+        convention would not properly work with pickle.  The attribute was
+        skipped leading to inconsistencies and failures if the unpickled
+        :class:`.MetaData` object were used to base additional tables
+        from.
+
     .. change::
         :tags: bug, postgresql
         :tickets: 3354
index a61389c777638b559ed1b184a6475d5f822dc886..ba461625752616564a365e8da7aa14f1e277db9f 100644 (file)
@@ -3194,11 +3194,14 @@ class MetaData(SchemaItem):
                 'schema': self.schema,
                 'schemas': self._schemas,
                 'sequences': self._sequences,
-                'fk_memos': self._fk_memos}
+                'fk_memos': self._fk_memos,
+                'naming_convention': self.naming_convention
+                }
 
     def __setstate__(self, state):
         self.tables = state['tables']
         self.schema = state['schema']
+        self.naming_convention = state['naming_convention']
         self._bind = None
         self._sequences = state['sequences']
         self._schemas = state['schemas']
index 83ab1fcf7a526226af5bab21467b6bb56c60709b..77ec26816615f28ac99b64e9c1f8636b7c1aabf2 100644 (file)
@@ -3253,3 +3253,16 @@ class NamingConventionTest(fixtures.TestBase, AssertsCompiledSQL):
         u1.append_constraint(ck1)
 
         eq_(ck1.name, "ck_user_foo")
+
+    def test_pickle_metadata(self):
+        m = MetaData(naming_convention={"pk": "%(table_name)s_pk"})
+
+        m2 = pickle.loads(pickle.dumps(m))
+
+        eq_(m2.naming_convention, {"pk": "%(table_name)s_pk"})
+
+        t2a = Table('t2', m, Column('id', Integer, primary_key=True))
+        t2b = Table('t2', m2, Column('id', Integer, primary_key=True))
+
+        eq_(t2a.primary_key.name, t2b.primary_key.name)
+        eq_(t2b.primary_key.name, "t2_pk")