From da0a8b913bc1336b85618edee0ef63ed96ea1ba0 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Tue, 11 Nov 2008 01:52:42 +0000 Subject: - Adjustments to the enhanced garbage collection on InstanceState to better guard against errors due to lost state. --- lib/sqlalchemy/orm/attributes.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/sqlalchemy/orm/attributes.py b/lib/sqlalchemy/orm/attributes.py index e80392d0c..662ea05d3 100644 --- a/lib/sqlalchemy/orm/attributes.py +++ b/lib/sqlalchemy/orm/attributes.py @@ -799,7 +799,6 @@ class InstanceState(object): runid = None expired_attributes = EMPTY_SET insert_order = None - dict = None def __init__(self, obj, manager): self.class_ = obj.__class__ @@ -820,15 +819,23 @@ class InstanceState(object): def dispose(self): if self.session_id: del self.session_id - del self.dict del self.obj + del self.dict def _cleanup(self, ref): self.dispose() def obj(self): return None - + + @util.memoized_property + def dict(self): + # return a blank dict + # if none is available, so that asynchronous gc + # doesn't blow up expiration operations in progress + # (usually expire_attributes) + return {} + @property def sort_key(self): return self.key and self.key[1] or self.insert_order @@ -969,9 +976,6 @@ class InstanceState(object): if key not in self.committed_state and key not in self.dict) def expire_attributes(self, attribute_names): - if self.dict is None: - return - self.expired_attributes = set(self.expired_attributes) if attribute_names is None: -- cgit v1.2.1