with transaction() statements have conflicting rollbacks

Bug #125118 reported by Aaron Swartz on 2007-07-10
2
Affects Status Importance Assigned to Milestone
web.py
Medium
Anand Chitipothu

Bug Description

See http://groups.google.com/group/webpy/browse_thread/thread/4009018b6346ffd3

Perhaps we should take rollback out altogether?

Aaron Swartz (aaronsw) on 2007-07-10
Changed in webpy:
assignee: nobody → anandology
importance: Undecided → Medium
status: New → Confirmed
Anand Chitipothu (anandology) wrote :

Consider the following code:

def f():
    web.transact()
    try:
        g()
    except:
        web.rollback()
    else:
        web.commit()

def g():
    web.transact()
     h()
     web.commit()

def h():
    raise Exception

Since g, didn't do rollback, the rollback in f is not really rolling back the correct transaction.

How about the following interface?

t = web.transact()
try:
    web.query('blah blah blah')
except:
    t.rollback()
    raise
else:
    t.commit()

Here we know what to rollback, so even if it is rolled back twice, it can be handled.

shall we consider it for web.py 0.3?

Anand Chitipothu (anandology) wrote :

Still better:

    t = web.transaction()
    try:
       do_something()
    except:
        t.rollback()
    else:
        t.commit()

if with stmt is supported:

    with web.transaction():
        do_something()

I'm not sure what you're saying.

The problem is that db_execute automatically calls rollback.

Aee you saying we should just require people to use with statements?

Anand Chitipothu (anandology) wrote :

On Dec 16, 2007 2:42 PM, Aaron Swartz <email address hidden> wrote:
> I'm not sure what you're saying.

I am saying that when you do rollback in a nested transaction, it is
not clear which level you are trying to rollback.
Assuming that rollback will rollback the latest transaction is not
always correct.

> The problem is that db_execute automatically calls rollback.

I fixed it like this.

http://codebrowse.launchpad.net/~anandology/webpy/webpy-0.23/revision/199

>
> Aee you saying we should just require people to use with statements?
>

No.

I am suggesting
    t = db.transaction()
    t.rollback()
instead of
   db.transact()
   db.rollback()

Aaron Swartz (aaronsw) wrote :

> I am suggesting
> t = db.transaction()
> t.rollback()
> instead of
> db.transact()
> db.rollback()

Ohhhh.

Clever. That makes sense.

Anand Chitipothu (anandology) wrote :

fixed in webpy-0.23. Still need to be fixed in webpy.dev.

Changed in webpy:
milestone: none → 0.3
Changed in webpy:
status: Confirmed → Fix Committed
Changed in webpy:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers