On Nov 17, 2012, at 1:16 AM, sajuptpm wrote:

> H, Michael Bayer
> Thanks
> 
> You are correct, the rollback in method1 rollbacking transaction in 
> main_method.
> I want to isolate transaction in main_method from rollback in method1.
> 
> I attached more code.
> 
> 
> from sqlalchemy.orm import scoped_session, sessionmaker
> maker = sessionmaker(autoflush=True, autocommit=False,expire_on_commit=False,
>                      extension=ZopeTransactionExtension())
> zopelessmaker = sessionmaker(autoflush=True, \
>                              autocommit=False, \
>                              expire_on_commit=False)
> DBSession = scoped_session(maker)
> 
> 
> 
> def main_method():
>     db_obj1 = DBModelclass1("Hello")    
>     DBSession.add(db_obj1)
>     DBSession.fush()
> 
>     for x in lst:
>         try:
>             method1(db_obj1.id)
>         excpt Exception, ex:
>             pass
> 
> 
> 
> def method1(id):
>     try:    
> 
>         s1 = DBSession()
>         s1.begin_nested()
>     db_obj2 = DBModelclass2("Test")
>     db_obj2.refname = "name_%s" %(id)
>         DBSession.add(db_obj2)
>         DBSession.fush()
> 
>         if some-codition:
>             raise Exception("Failedd")
> 
>         s1.commit()
>     except Exception, ex:
>         s1.rollback()
>         raise ex 

other than the typos, as well as the multiple calls to "method1()" for every 
"x" in a list where the "x" is apparently ignored, there is nothing obviously 
wrong with this code.  If you're using begin_nested(), it has to be on a 
platform that supports SAVEPOINT.  Currently Postgresql and MySQL with InnoDB 
are the two main platforms supported.

As I have already stated in my previous email, turning on echo=True and/or 
echo='debug' will illustrate the SQL being emitted as well as where 
transactions start and end.  This is a *critical* step to being able to 
understand your issue.  I'd also recommend using pdb so that you can step into 
the code and examine the state of the database and program state one line at a 
time.


-- 
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 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to