I'd certainly never do that - no matter what type of application is running, 
its always best to use transaction-per-logical operation, which means usually, 
transactions are short.  If the transactions are necessarily long, a database 
failure in the middle means the operation just fails, but there was no option 
there since you needed that long running transaction.

If the app is a console app that stays open for a long time in some kind of 
loop, use a new Session() for each iteration of the loop, or for each 5- minute 
operation its doing, or whatever.

So the answer is not to try/except everything, its to frame the usage of a 
particular transaction around the logical span of the operations you're 
performing.





On Jan 13, 2011, at 2:47 AM, can xiang wrote:

> Hi,
> 
> sqlalchemy is such a piece of great work. I'm very happy with it,
> while I indeed get a problem.
> 
> I use sqlalchemy 0.6.6 in a non-threaded  app. session is created at
> module level at once. autocommit is set to False.
> 
> I see log shows:
>         user = user_session.query(User).filter(User.hw_id ==
> args['hw_id']).first()
> with the following exception:
>         InvalidRequestError: Can't reconnect until invalid
> transaction is rolled back
> 
> the mysql server restarted at that time.
> 
> I check the docs, it says this may caused by a error while commit and
> without rollback for that session. But the above query is single query
> without a transaction and with no data commit.
> 
> If I have to wrap all QUERY operations in try except and rollback
> manually? It's so tedious and not so nice, any advice?
> 
> -- 
> 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.
> 

-- 
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