Hi,

I have a problem with Session.begin_nested()  on mysql InnoDB.

I create some object and save its to db, pseudo code below:
...
try:
   r = ...
   Session.add(r)
   Session.flush() <- waiting for raise Exception if some db error
   result = external_function_also_using_db()
   prepared_result = ....
   Session.add(prepared_result)
except:
   Session.rollback()
else:
   Session.commit()

########################

def external_function_also_using_db():
    Session.begin_nested()
   # some stuff
   ...
# save logs to db in nested or other transaction, nested not works as expected
   try:
       Session.add(...)
   except:
      ...
   else:
       Session.commit() # <- have to be independent transaction
   return result
########################

Problem exist when first is commit and next is rollback, result = nothing saved I want that logs has been saved but top object (r and prepared_result) has been rollback

I think I should use 2 connection to the same db (user,db).

How can I do?

engine2 = engine_from_config(config, 'sqlalchemy.')
Session2 = scoped_session(sessionmaker())
Session2.configure(bind=engine2)

is enough or  too much?

Best Regards,
Tomasz



--
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" 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/pylons-discuss?hl=en.

Reply via email to