On Jan 22, 1:56 pm, Jose Soares <[EMAIL PROTECTED]> wrote: > Hello, > > Could someone please, explain me what's wrong with thistransaction? > .... > File > "/usr/lib/python2.4/site-packages/TurboGears-1.0-py2.4.egg/turbogears/database.py", > line 303, in sa_rwt> transaction.commit() > File "build/bdist.linux-i686/egg/sqlalchemy/orm/session.py", line 54, in > commit > File "build/bdist.linux-i686/egg/sqlalchemy/engine/base.py", line 389, in > commitInvalidRequestError: Thistransactionisinactive > --------- > > def save_user(data,user,anagrafica): > transaction= session.create_transaction() > try: > for f in user.ruoli: > session.delete(f) > session.flush() > for item in data.get('dettaglio'): > if item.get('cod_ruolo'): > user.ruoli.append(UserGroup( > id_operatore = item.get('id_operatore'), > ) > ) > user.data_inizio_attivita = data.get('data_inizio_attivita') > anagrafica.nome = data.get('display_name') > session.save(user) > session.save(anagrafica) > session.flush() > transaction.commit() > except: > transaction.rollback() > > jo Jose, there has been some discussion of this on the TurboGears Google group. The thread is at http://groups.google.com/group/turbogears/browse_thread/thread/a81bfa81143c3a82 (SQLAlchemy and run_with_transaction) Essentially, the @expose() decorator wraps the session you are using in a transaction (sa_rwt) within which the controller method runs. When the controller raises an exception and rolls back, the commit() that happens after the controller code block is trying to commit an already rolled back transaction. The solution I went (from the TurboGears group discussion) was to create a decorator to use with my controller methods that need transactions that overrides this "feature" of @expose(). Mike S. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---