diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2006-03-24 23:06:07 +0000 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2006-03-24 23:06:07 +0000 |
commit | 03bb7a9641eb936fc6f5867a9df57f348aa674c9 (patch) | |
tree | fbca5e967792ceb52b0b0e23cbfaf58fd947580b /lib/sqlalchemy/attributes.py | |
parent | b1deaf1fb76e2ed60da4bea5e1b5cc2b732b8a23 (diff) | |
download | sqlalchemy-03bb7a9641eb936fc6f5867a9df57f348aa674c9.tar.gz |
added overrideable managed_attribute_dict() function which can be changed
to eliminate circular references on objects
Diffstat (limited to 'lib/sqlalchemy/attributes.py')
-rw-r--r-- | lib/sqlalchemy/attributes.py | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/sqlalchemy/attributes.py b/lib/sqlalchemy/attributes.py index 437baeea8..bd730a109 100644 --- a/lib/sqlalchemy/attributes.py +++ b/lib/sqlalchemy/attributes.py @@ -28,6 +28,7 @@ via the GenericBackrefExtension object. """ import util +import weakref from exceptions import * class SmartProperty(object): @@ -351,7 +352,7 @@ class AttributeManager(object): def init_attr(self, obj): """sets up the _managed_attributes dictionary on an object. this happens anyway regardless of this method being called, but saves on KeyErrors being thrown in get_history().""" - d = {} + d = managed_attribute_dict() obj.__dict__['_managed_attributes'] = d cls_managed = self.class_managed(obj.__class__) for value in cls_managed.values(): @@ -376,7 +377,7 @@ class AttributeManager(object): trigger = obj.__dict__.pop('_managed_trigger', None) if trigger: trigger() - attr = {} + attr = managed_attribute_dict() obj.__dict__['_managed_attributes'] = attr return attr @@ -458,3 +459,9 @@ class AttributeManager(object): self.class_managed(class_)[key] = createprop setattr(class_, key, self.create_prop(class_, key, uselist)) +# make this function return a weakref.WeakValueDictionary to avoid +# creating circular references in objects +def managed_attribute_dict(): + return {} +# return weakref.WeakValueDictionary() + |