summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2015-02-18 14:08:40 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2015-02-18 14:08:40 -0500
commit15e670fbc4bdfc3d1521163677c5e874f430b958 (patch)
tree9c36b66607caf23a33dad77a63821cf7dd198cca
parent99b535bbd1dab7bd2dcbc61dedec127641b1be2e (diff)
downloadsqlalchemy-15e670fbc4bdfc3d1521163677c5e874f430b958.tar.gz
- add compatiblity for 0.9 style pickle
-rw-r--r--lib/sqlalchemy/orm/state.py10
-rw-r--r--test/orm/test_pickled.py31
2 files changed, 40 insertions, 1 deletions
diff --git a/lib/sqlalchemy/orm/state.py b/lib/sqlalchemy/orm/state.py
index 4d7bd539c..7a4d2e13b 100644
--- a/lib/sqlalchemy/orm/state.py
+++ b/lib/sqlalchemy/orm/state.py
@@ -338,7 +338,15 @@ class InstanceState(interfaces.InspectionAttr):
self.modified = state_dict.get('modified', False)
self.expired = state_dict.get('expired', False)
self.callables = state_dict.get('callables', {})
- self.expired_attributes = state_dict['expired_attributes']
+ try:
+ self.expired_attributes = state_dict['expired_attributes']
+ except KeyError:
+ self.expired_attributes = set()
+ # 0.9 and earlier compat
+ for k in list(self.callables):
+ if self.callables[k] is self:
+ self.expired_attributes.add(k)
+ del self.callables[k]
self.__dict__.update([
(k, state_dict[k]) for k in (
diff --git a/test/orm/test_pickled.py b/test/orm/test_pickled.py
index 35f1b19d1..db2a27c77 100644
--- a/test/orm/test_pickled.py
+++ b/test/orm/test_pickled.py
@@ -11,6 +11,8 @@ from sqlalchemy.orm import mapper, relationship, create_session, \
clear_mappers, exc as orm_exc,\
configure_mappers, Session, lazyload_all,\
lazyload, aliased
+from sqlalchemy.orm import state as sa_state
+from sqlalchemy.orm import instrumentation
from sqlalchemy.orm.collections import attribute_mapped_collection, \
column_mapped_collection
from sqlalchemy.testing import fixtures
@@ -241,6 +243,35 @@ class PickleTest(fixtures.MappedTest):
u2 = loads(dumps(u1))
eq_(u1, u2)
+ def test_09_pickle(self):
+ users = self.tables.users
+ mapper(User, users)
+ sess = Session()
+ sess.add(User(id=1, name='ed'))
+ sess.commit()
+ sess.close()
+
+ inst = User(id=1, name='ed')
+ del inst._sa_instance_state
+
+ state = sa_state.InstanceState.__new__(sa_state.InstanceState)
+ state_09 = {
+ 'class_': User,
+ 'modified': False,
+ 'committed_state': {},
+ 'instance': inst,
+ 'callables': {'name': state, 'id': state},
+ 'key': (User, (1,)),
+ 'expired': True}
+ manager = instrumentation._SerializeManager.__new__(
+ instrumentation._SerializeManager)
+ manager.class_ = User
+ state_09['manager'] = manager
+ state.__setstate__(state_09)
+
+ sess = Session()
+ sess.add(inst)
+ eq_(inst.name, 'ed')
@testing.requires.non_broken_pickle
def test_options_with_descriptors(self):