I wish to determine if open a transaction inside these guys safe and urged?

I've got a method:

def foo():
    session.begin
    try:
          stuffs
    except Exception, e:
         session.rollback()
         raise e
    session.commit()

along with a method that calls the first, in the transaction:

def bar():
    stuffs
    try:
         foo()   #<<<< there it is :)
         stuffs
    except Exception, e:
        session.rollback()
        raise e
    session.commit()

basically get and exception around the foo method, all of the procedures is going to be folded back? and anything else works all right? thanks!!

you will find two ways two nest transactions in SQLAlchemy. The first is virtual transactions, where SQLAlchemy monitors the number of begin's you've released and issues the commit only if the outermost transaction commits. The rollback however is released immediately. Since the transaction is virtual - i.e. the database knows nothing from the nesting, you cannot so something with that session following the rollback before you rollback all of the outer transactions too. To permit the employment virtual transactions add subtransactions=True argument towards the begin() call. This feature is available to let you use transaction control inside functions that may call one another without keeping track if you're in the transaction or otherwise. For this to create sense, configure the session with autocommit=True and try to problem a session.begin(subtransactions=True) inside a transactional function.

Another method to nest transactions is by using real nested transactions. They're implemented using savepoints. Should you rollback a nested transaction, all changes made within that transaction are folded back, however the outer transaction remains functional and then any changes produced by the outer transaction remain. To make use of nested transaction problem session.begin(nested=True) or simply session.begin_nested(). Nested transactions aren't supported for those databases. SQLAlchemy test suite library configuration function sqlalchemy.test.requires.savepoints states this concerning the support:

    emits_warning_on('mssql', 'Savepoint support in mssql is experimental and may lead to data loss.'),
    no_support('access', 'not supported by database'),
    no_support('sqlite', 'not supported by database'),
    no_support('sybase', 'FIXME: guessing, needs confirmation'),
    exclude('mysql', '<', (5, 0, 3), 'not supported by database')

On PostgreSQL SQLAlchemy nested transactions work all right.

You cannot, PostgreSQL does not support subtransactions. You might like to use savepoints, but thats another thing.

On PostgreSQL nested transactions work all right.

Well, you are not getting a mistake (only a warning), that's true. However, you can't commit the interior transaction and rollback the outer transaction, the outer transaction will even rollback the interior transaction.

BEGIN

Place INTO x(foo) VALUES('John')

BEGIN -- WARNING!

Place INTO y(bar) VALUES('Jane')

COMMIT -- commit inner transaction

ROLLBACK -- will rollback both card inserts, not only the very first, the main one in table "x"

To my understanding, Oracle is among the couple of which has this method.