I have some questions about sa_rwt.  Below is the code for reference.
If a transaction is rolled back and a redirect is issued, it doesn't
look like it would catch InvalidRequestError.  Also, when catching
InternalRedirect, what does "else: raise" actually do? Doesn't "except
Exception, e" catch everything? So it looks to me like
InvalidRequestError needs to be caught within the "except
(cherrypy.HTTPRedirect,cherrypy.InternalRedirect)" block.

-Randall

def sa_rwt(func, *args, **kw):
    log.debug("New SA transaction")
    del session.context.current
    req = cherrypy.request
    req.sa_transaction = session.create_transaction()
    try:
        retval = func(*args, **kw)
        req.sa_transaction.commit()
    except (cherrypy.HTTPRedirect,cherrypy.InternalRedirect):
        try:
            req.sa_transaction.commit()
        except Exception,e:
            retval = dispatch_exception(e,args,kw)
        else:
            raise
    except InvalidRequestError, e:
        # do nothing here transaction
        # has been already rolledback and
        # we should just display output
        pass

    except Exception, e:
        req.sa_transaction.rollback()
        retval = dispatch_exception(e,args,kw)

    return retval

On Aug 11, 4:13 pm, Randall <[EMAIL PROTECTED]> wrote:
> I see the latest version of TG does this by catching
> InvalidRequestError.  That's funny because I submitted a patch doing
> just that before I realized it.  Still, there are conditions when
> InvalidRequestError should still be raised, so I think TG should check
> the error message to make sure it was raised because of an inactive
> transaction.  I'll create a new ticket, but here is what I have in
> mind:
>
>      except InvalidRequestError, e:
>         if 'transaction is inactive' not in str(e):
>             raise
>
> --Randall
>
> On Aug 10, 11:49 pm, Randall <[EMAIL PROTECTED]> wrote:
>
> > Trying to rollback a transaction ends with an error because TG
> > ultimately trys to commit it. I found and workaround in a thread here,
> > but I'm wondering if TG could check the state of a transaction and not
> > attempt a commit if the transaction is not active.  Transaction has an
> > attribute is_active that I believe could be useful for this.  I'm not
> > sure of the best way to access it, but I found it playing around like
> > this:
>
> > trans.connections.values()[0][1].is_active
>
> > where trans is returned from session.create_transaction
>
> > I'm thinking TG could do something like this:
>
> > if transaction.is_active:
> >     session_trans.commit()
> > else:
> >     # need to do anything ?
> >     pass


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to