[ZODB-Dev] Checking transaction status?

Jim Fulton jim@digicool.com
Tue, 10 Jul 2001 15:07:41 -0400


Michel Pelletier wrote:
> 
> On Tue, 10 Jul 2001, Christian Robottom Reis wrote:
> 
> >
> > Hi,
> >
> > I'm implementing a simple 'check if data has been changed and warn user
> > it's going to be lost' type of check to my app. I've implemented my
> > interface to set values to the data instance it holds (thus getting free
> > 1-level Undo support, whee), and now I want to check to see if the object
> > has been dirtied and warn the user if so. Is there an easy way to check if
> > a transaction has been started?
> 
> I just spoke with Jim about this (one of the advantages of being in Fburg
> for a few days...).  Effectively, there is always a started
> transaction.  Opening a connection begins a transaction, both commit() and
> abort() start a new transaction.  There shouldn't be any point, currently,
> where you are not working in a transaction.
> 
> So what's the point of begin()?  So you can be explicit about starting a
> new transaction.  Instead of just saying blah blah blah commit().  You do
> a begin() first so that you are absolutely certainly where the transaction
> boundaries are.
> 
> Hope to see some of you at the EuroZope conf in Berlin on Thursday!

This answered the question he asked, but not the question he meant to ask.
Christian meant to ask: "Is there an easy way to check if
a transaction has been started and has pending modifications?".

The answer is yes, but it requires cheating. :/

There ought to be an interface on transactions to find out
of they have pending changes, but there isn't. You can look
at their '_objects' attribute to see if it is non-empty.
Of course, this might be broken in some future version, but if
we do break it, we'll at least provide an API to do the right
thing.

Jim


--
Jim Fulton           mailto:jim@digicool.com   Python Powered!        
Technical Director   (888) 344-4332            http://www.python.org  
Digital Creations    http://www.digicool.com   http://www.zope.org