summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES6
-rw-r--r--lib/sqlalchemy/schema.py5
-rw-r--r--test/sql/test_metadata.py39
3 files changed, 45 insertions, 5 deletions
diff --git a/CHANGES b/CHANGES
index 60a09b2ea..7cab20449 100644
--- a/CHANGES
+++ b/CHANGES
@@ -11,6 +11,12 @@ CHANGES
This so that code which does something like
Integer(11) still succeeds.
+ - Fixed regression whereby MetaData() coming
+ back from unpickling did not keep track of
+ new things it keeps track of now, i.e.
+ collection of Sequence objects, list
+ of schema names. [ticket:2104]
+
0.7.0b3
=======
- general
diff --git a/lib/sqlalchemy/schema.py b/lib/sqlalchemy/schema.py
index bc3eac213..c8d00f407 100644
--- a/lib/sqlalchemy/schema.py
+++ b/lib/sqlalchemy/schema.py
@@ -2101,7 +2101,6 @@ class MetaData(SchemaItem):
self._schemas = set()
self._sequences = set()
self.bind = bind
- self.metadata = self
if reflect:
if not bind:
raise exc.ArgumentError(
@@ -2132,11 +2131,13 @@ class MetaData(SchemaItem):
if t.schema is not None])
def __getstate__(self):
- return {'tables': self.tables}
+ return {'tables': self.tables, 'schemas':self._schemas}
def __setstate__(self, state):
self.tables = state['tables']
self._bind = None
+ self._sequences = set()
+ self._schemas = state['schemas']
def is_bound(self):
"""True if this MetaData is bound to an Engine or Connection."""
diff --git a/test/sql/test_metadata.py b/test/sql/test_metadata.py
index 4c0abd1f0..04bc0c345 100644
--- a/test/sql/test_metadata.py
+++ b/test/sql/test_metadata.py
@@ -239,13 +239,15 @@ class MetaDataTest(TestBase, ComparesTables):
meta3 = pickle.loads(pickle.dumps(meta2))
assert meta3.bind is None
assert meta3.tables['mytable'] is not t1
+
return (meta3.tables['mytable'], meta3.tables['othertable'])
meta.create_all(testing.db)
try:
- for test, has_constraints, reflect in (test_to_metadata,
- True, False), (test_pickle, True, False), \
- (test_pickle_via_reflect, False, True):
+ for test, has_constraints, reflect in \
+ (test_to_metadata, True, False), \
+ (test_pickle, True, False), \
+ (test_pickle_via_reflect, False, True):
table_c, table2_c = test()
self.assert_tables_equal(table, table_c)
self.assert_tables_equal(table2, table2_c)
@@ -281,9 +283,40 @@ class MetaDataTest(TestBase, ComparesTables):
assert False
assert c.columns.contains_column(table_c.c.name)
assert not c.columns.contains_column(table.c.name)
+
+
finally:
meta.drop_all(testing.db)
+ def test_pickle_metadata_sequence(self):
+ m1 = MetaData()
+ Table('a',m1,
+ Column('id',Integer,primary_key=True),
+ Column('x', Integer, Sequence("x_seq")))
+
+ m2 = pickle.loads(pickle.dumps(m1))
+
+ t2 = Table('a', m2,
+ Column('id',Integer,primary_key=True),
+ Column('x', Integer, Sequence("x_seq")),
+ useexisting=True)
+
+ eq_(m2._sequences, set([t2.c.x.default]))
+
+ def test_pickle_metadata_schema(self):
+ m1 = MetaData()
+ Table('a',m1,
+ Column('id',Integer,primary_key=True),
+ Column('x', Integer, Sequence("x_seq")),
+ schema='y')
+
+ m2 = pickle.loads(pickle.dumps(m1))
+
+ t2 = Table('a', m2, schema='y',
+ useexisting=True)
+
+ eq_(m2._schemas, m1._schemas)
+
def test_tometadata_with_schema(self):
meta = MetaData()