summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHsiaoming Yang <me@lepture.com>2015-05-25 18:36:49 +0800
committerHsiaoming Yang <me@lepture.com>2015-05-25 18:36:49 +0800
commit3bf0cf936767315a6f95d26d3b4857c885652b97 (patch)
tree85d8a1f4d857d413cd46e80d47b06cb2d4cae8e7
parent9157911013532e081f9ec6e29e7a4c271438f8ab (diff)
downloadsqlalchemy-pr/174.tar.gz
Fixed unpickle bug when val in ext.mutable.values has no _parentspr/174
It happens on these conditions: 1. ``expire_on_commit=False`` option on Session. 2. Using a custom type, such as JSONEncodedDict. 3. Column with a default value. Here is an example:: class Foo(Base): id = Column(Integer, primary_key=True) info = Column(JSONEncodedDict, default={}) Saving a Foo instance into memcache, and then get it out of memcache. It would raise an exception:: def unpickle(state, state_dict): if 'ext.mutable.values' in state_dict: for val in state_dict['ext.mutable.values']: > val._parents[state.obj()] = key E AttributeError: 'dict' object has no attribute '_parents' Because the saved value in pickle function is a pure dict. It has no '_parents'.
-rw-r--r--lib/sqlalchemy/ext/mutable.py2
1 files changed, 1 insertions, 1 deletions
diff --git a/lib/sqlalchemy/ext/mutable.py b/lib/sqlalchemy/ext/mutable.py
index 501b18f39..1dd2337d4 100644
--- a/lib/sqlalchemy/ext/mutable.py
+++ b/lib/sqlalchemy/ext/mutable.py
@@ -478,7 +478,7 @@ class MutableBase(object):
def pickle(state, state_dict):
val = state.dict.get(key, None)
- if val is not None:
+ if val is not None and hasattr(val, '_parents'):
if 'ext.mutable.values' not in state_dict:
state_dict['ext.mutable.values'] = []
state_dict['ext.mutable.values'].append(val)