]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
fixed small pickle bug with lazy loaders [ticket:265]
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 6 Aug 2006 16:48:30 +0000 (16:48 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 6 Aug 2006 16:48:30 +0000 (16:48 +0000)
CHANGES
lib/sqlalchemy/attributes.py
test/base/attributes.py

diff --git a/CHANGES b/CHANGES
index 2c5c28df5b25c1d3b954e8ab61ecb974fb977769..36c27d6cc2b371668434367e80334ccf0005a140 100644 (file)
--- 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
index 724f1c807ceeab7915f9e48bdac104f087ff4c88..1c4f07ac6c3c2fc33846ca06b2ec01116ccf21be 100644 (file)
@@ -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.
index 5f555a7e60a79846ae47f4ea9f24e66ed93ac21f..233c4458f3ed085e0467cf688b49c1a97bd4a43c 100644 (file)
@@ -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)