From: Mike Bayer Date: Sun, 6 Aug 2006 16:48:30 +0000 (+0000) Subject: fixed small pickle bug with lazy loaders [ticket:265] X-Git-Tag: rel_0_2_7~31 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=63519a4f0472cf2265c0b915e6d153e358a3ebdd;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git fixed small pickle bug with lazy loaders [ticket:265] --- diff --git a/CHANGES b/CHANGES index 2c5c28df5b..36c27d6cc2 100644 --- a/CHANGES +++ b/CHANGES @@ -22,6 +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] 0.2.6 - big overhaul to schema to allow truly composite primary and foreign diff --git a/lib/sqlalchemy/attributes.py b/lib/sqlalchemy/attributes.py index 724f1c807c..1c4f07ac6c 100644 --- a/lib/sqlalchemy/attributes.py +++ b/lib/sqlalchemy/attributes.py @@ -34,13 +34,13 @@ class InstrumentedAttribute(object): def hasparent(self, item): """returns True if the given item is attached to a parent object via the attribute represented by this InstrumentedAttribute.""" - return item._state.get(('hasparent', self)) + return item._state.get(('hasparent', id(self))) def sethasparent(self, item, value): """sets a boolean flag on the given item corresponding to whether or not it is attached to a parent object via the attribute represented by this InstrumentedAttribute.""" if item is not None: - item._state[('hasparent', self)] = value + item._state[('hasparent', id(self))] = value def get_history(self, obj, passive=False): """return a new AttributeHistory object for the given object/this attribute's key. diff --git a/test/base/attributes.py b/test/base/attributes.py index 5f555a7e60..233c4458f3 100644 --- a/test/base/attributes.py +++ b/test/base/attributes.py @@ -6,6 +6,7 @@ import pickle class MyTest(object):pass +class MyTest2(object):pass class AttributesTest(PersistTest): """tests for the attributes.py module, which deals with tracking attribute changes on an object.""" @@ -43,7 +44,15 @@ class AttributesTest(PersistTest): manager.register_attribute(MyTest, 'user_id', uselist = False) manager.register_attribute(MyTest, 'user_name', uselist = False) manager.register_attribute(MyTest, 'email_address', uselist = False) + manager.register_attribute(MyTest2, 'a', uselist = False) + manager.register_attribute(MyTest2, 'b', uselist = False) + # shouldnt be pickling callables at the class level + def somecallable(*args): + return None + manager.register_attribute(MyTest, 'mt2', uselist = False, trackparent=True, callable_=somecallable) x = MyTest() + x.mt2 = MyTest2() + x.user_id=7 s = pickle.dumps(x) x2 = pickle.loads(s)