]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
added overrideable managed_attribute_dict() function which can be changed
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 24 Mar 2006 23:06:07 +0000 (23:06 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 24 Mar 2006 23:06:07 +0000 (23:06 +0000)
to eliminate circular references on objects

lib/sqlalchemy/attributes.py

index 437baeea8480f14200fe8123a7b49b41c9c0c49b..bd730a10917103e28fbb71dc3011b3475236c8b8 100644 (file)
@@ -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()
+