summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES1
-rw-r--r--lib/sqlalchemy/attributes.py4
-rw-r--r--test/base/attributes.py9
3 files changed, 12 insertions, 2 deletions
diff --git a/CHANGES b/CHANGES
index 2c5c28df5..36c27d6cc 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 724f1c807..1c4f07ac6 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 5f555a7e6..233c4458f 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)