[Zope-dev] Re: [ZCM] [ZC] 869/ 5 Comment "Broken transaction handling in case of exceptions"

Toby Dickenson tdickenson@geminidataloggers.com
Tue, 8 Apr 2003 08:11:43 +0100


--Boundary-00=_vYnk+oix79ZMCbc
Content-Type: text/plain;
  charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

On Monday 07 April 2003 10:09 pm, Florent Guillaume wrote:

> Ok, from your exlanations, MemberDataTool should be now safe -- I
> patched it a few weeks ago to clear the cache at the end of the
> transaction using REQUEST._hold.

BTW, I use the attatched class to delete an attribute from an object at the 
end of a transaction. This is a little safer than REQUEST._hold in cases 
where request boundares are not aligned with transactions. Should this go in 
ZODB somewhere?

> > > Is all this wrong ?
> >
> > ?
>
> I meant, is all the above code using ad-hoc caches buggy in one way or
> another?

I meant, is it buggy enough to need fixing?

-- 
Toby Dickenson
http://www.geminidataloggers.com/people/tdickenson
--Boundary-00=_vYnk+oix79ZMCbc
Content-Type: text/x-python;
  charset="iso-8859-1";
  name="AttributeCleaner.py"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="AttributeCleaner.py"

"""
attribute_cleaner

A class to remove an attribute from an object at the end of a 
transaction. This is useful for attributes that hold
transaction-specific caches.

Normal operation is::

    if self._v_cache is None:
        self._v_cache = create_data_to_cache()
        attribute_cleaner(self,'_v_cache')
"""

class attribute_cleaner:
    def __init__(self,client,attr):
        self.client = client
        self.attr = attr
        get_transaction().register(self)

    def sortKey(self):
        return repr(self)

    def ClearCache(self,*args):
        try:
            delattr(self.client, self.attr)
        except AttributeError:
            pass
        except KeyError:
            pass

    tpc_finish = tpc_abort = abort = abort_sub = ClearCache

    def tpc_begin(self,transaction,subtransaction=None): pass
    def commit(self,object,transaction): pass
    def tpc_vote(self,transaction):      pass
    def commit_sub(self,transaction):    pass


--Boundary-00=_vYnk+oix79ZMCbc--