[Zope-DB] DA's violating transactional assertions

M.-A. Lemburg mal@lemburg.com
Fri, 24 Jan 2003 10:39:27 +0100


Dieter Maurer wrote:
> Recently, I saw several DA's that contains the following functionality
> in their "query" method:
> 
>    ....
>    try:
>      ...
>      execute SQL command
>      ...
>    except <some transient exceptions>:
>      close database connection
>      reopen databse connection
>      retry query
> 
> While this is *very* fine from a practical point of view (it
> recovers from most transient database problems), in invalidates
> Zope's transactional assertions.
> 
> Assume the following case:
> 
>        Zope request start (Zope transaction begins)
> 
>        1. SQL Method - succeeds
> 
>        2. SQL Method - transient exception
>           this will close the database connection
> 	  and thereby performing an implicit transaction rollback
> 	  (for this DA)
> 	  Retry succeeds
> 
>        Zope request ends (Zope transaction committed)
> 
> The transactional assertion (all or nothing) may be violated
> for Zope's transaction, as it may contain the effect
> of the 2. SQL Method call but have lost that of the first
> one.

This is only true if the first and second SQL Method
calls work on the same physical database connection. But that's
probably the typcial situation for most DAs.

> DA's should handle transient exceptions not by retrying the
> the query themselves but by raising a (special) exception
> derived from "ConflictError" after they closed and reopened the
> connection.
> This will cause Zope to abort its transaction and then
> retry its complete transaction again.

This would be much safer, yes. Is there such an exception
or would using a subclass of ConflictError suffice ?

-- 
Marc-Andre Lemburg
CEO eGenix.com Software GmbH
_______________________________________________________________________
eGenix.com -- Makers of the Python mx Extensions: mxDateTime,mxODBC,...
Python Consulting:                               http://www.egenix.com/
Python Software:                    http://www.egenix.com/files/python/