From: Mike Bayer Date: Tue, 8 Aug 2006 01:02:16 +0000 (+0000) Subject: adjusted __getstate__ on InstrumentedList to further avoid callables getting stuck... X-Git-Tag: rel_0_2_7~28 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aff1798c36acc814b0b27497101b0a36b9c8683c;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git adjusted __getstate__ on InstrumentedList to further avoid callables getting stuck in there... --- diff --git a/CHANGES b/CHANGES index 83ea698d83..5dd60be3a3 100644 --- a/CHANGES +++ b/CHANGES @@ -22,7 +22,7 @@ succeeded. added a test script to attempt testing this. - SingletonThreadPool has a size and does a cleanup pass, so that only a given number of thread-local connections stay around (needed for sqlite applications that dispose of threads en masse) -- fixed small pickle bug with lazy loaders [ticket:265] +- fixed small pickle bug(s) with lazy loaders [ticket:265] [ticket:267] - fixed possible error in mysql reflection where certain versions return an array instead of string for SHOW CREATE TABLE call diff --git a/lib/sqlalchemy/attributes.py b/lib/sqlalchemy/attributes.py index 1c4f07ac6c..c709afe3dc 100644 --- a/lib/sqlalchemy/attributes.py +++ b/lib/sqlalchemy/attributes.py @@ -300,14 +300,16 @@ class InstrumentedList(object): self[:] = [] def __getstate__(self): - """implemented to allow pickling, since __obj is a weakref.""" - return {'key':self.key, 'obj':self.obj, 'data':self.data, 'attr':self.attr} + """implemented to allow pickling, since __obj is a weakref, also the InstrumentedAttribute has callables + attached to it""" + return {'key':self.key, 'obj':self.obj, 'data':self.data} def __setstate__(self, d): - """implemented to allow pickling, since __obj is a weakref.""" + """implemented to allow pickling, since __obj is a weakref, also the InstrumentedAttribute has callables + attached to it""" self.key = d['key'] self.__obj = weakref.ref(d['obj']) self.data = d['data'] - self.attr = d['attr'] + self.attr = getattr(d['obj'].__class__, self.key) obj = property(lambda s:s.__obj()) diff --git a/test/base/attributes.py b/test/base/attributes.py index 233c4458f3..d3ca349316 100644 --- a/test/base/attributes.py +++ b/test/base/attributes.py @@ -49,9 +49,9 @@ class AttributesTest(PersistTest): # shouldnt be pickling callables at the class level def somecallable(*args): return None - manager.register_attribute(MyTest, 'mt2', uselist = False, trackparent=True, callable_=somecallable) + manager.register_attribute(MyTest, 'mt2', uselist = True, trackparent=True, callable_=somecallable) x = MyTest() - x.mt2 = MyTest2() + x.mt2.append(MyTest2()) x.user_id=7 s = pickle.dumps(x)