From dd061f40b4b8fd06bec0b75dd245aa043694dd5f Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sat, 10 Jun 2006 19:40:26 +0000 Subject: [PATCH] "parent track" function needed to be more specific to the parent class --- lib/sqlalchemy/attributes.py | 4 ++-- test/base/attributes.py | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/lib/sqlalchemy/attributes.py b/lib/sqlalchemy/attributes.py index c285ea50c0..07b395fee0 100644 --- a/lib/sqlalchemy/attributes.py +++ b/lib/sqlalchemy/attributes.py @@ -95,10 +95,10 @@ class ManagedAttribute(object): def plain_init(self, *args, **kwargs): pass def hasparent(self, item): - return item.__class__._attribute_manager.attribute_history(item).get('_hasparent_' + self.key) + return item.__class__._attribute_manager.attribute_history(item).get(('_hasparent_', self.obj.__class__, self.key)) def sethasparent(self, item, value): if item is not None: - item.__class__._attribute_manager.attribute_history(item)['_hasparent_' + self.key] = value + item.__class__._attribute_manager.attribute_history(item)[('_hasparent_', self.obj.__class__, self.key)] = value class ScalarAttribute(ManagedAttribute): """Used by AttributeManager to track the history of a scalar attribute diff --git a/test/base/attributes.py b/test/base/attributes.py index bff864fa69..382e9863ef 100644 --- a/test/base/attributes.py +++ b/test/base/attributes.py @@ -166,6 +166,31 @@ class AttributesTest(PersistTest): assert y.element == 'this is the bar attr' assert x.element2 == 'this is the shared attr' assert y.element2 == 'this is the shared attr' + + def testparenttrack(self): + class Foo(object):pass + class Bar(object):pass + + manager = attributes.AttributeManager() + + manager.register_attribute(Foo, 'element', uselist=False, trackparent=True) + manager.register_attribute(Bar, 'element', uselist=False, trackparent=True) + + f1 = Foo() + f2 = Foo() + b1 = Bar() + b2 = Bar() + + f1.element = b1 + b2.element = f2 + + assert manager.get_history(f1, 'element').hasparent(b1) + assert not manager.get_history(f1, 'element').hasparent(b2) + assert not manager.get_history(f1, 'element').hasparent(f2) + assert manager.get_history(b2, 'element').hasparent(f2) + + b2.element = None + assert not manager.get_history(b2, 'element').hasparent(f2) if __name__ == "__main__": unittest.main() -- 2.47.2