From: Mike Bayer Date: Wed, 6 Dec 2006 21:37:25 +0000 (+0000) Subject: moved _impl_dict to an external weakref so that TypeEngine objects can be pickled X-Git-Tag: rel_0_3_2~20 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=21d4e2a96eb8f505e8d2c942204917477c4323d3;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git moved _impl_dict to an external weakref so that TypeEngine objects can be pickled --- diff --git a/lib/sqlalchemy/types.py b/lib/sqlalchemy/types.py index 08f2c98436..eddb5d306f 100644 --- a/lib/sqlalchemy/types.py +++ b/lib/sqlalchemy/types.py @@ -12,19 +12,20 @@ __all__ = [ 'TypeEngine', 'TypeDecorator', 'NullTypeEngine', ] from sqlalchemy import util, exceptions -import inspect +import inspect, weakref try: import cPickle as pickle except: import pickle +_impl_cache = weakref.WeakKeyDictionary() + class AbstractType(object): def _get_impl_dict(self): try: - return self._impl_dict - except AttributeError: - self._impl_dict = {} - return self._impl_dict + return _impl_cache[self] + except KeyError: + return _impl_cache.setdefault(self, {}) impl_dict = property(_get_impl_dict) def copy_value(self, value):