On Jan 25, 2013, at 4:33 PM, Pedro Werneck wrote:

> I'm having a problem with many concurrent scripts, workers and uwsgi 
> instances writing and reading the same tables and rows almost simultaneously, 
> and sometimes one of them seems to get an older state, even from an object it 
> never touched in the first place and I'm querying for the first time. I find 
> that weird, but I assume it has to do with the database isolation level.

sure, if the updates to that row are still pending in an uncommitted 
transaction, the outside world would still see the old data.


> 
> The problem is, how to adequately deal with that and make sure it never 
> happens? I added a session.commit() before doing anything and it works, I 
> assume rollback would work too. Is there any better solution? 

You should be committing *after* you've done some work.   Then when a new 
request comes in, it should start out with a brand new Session which will make 
a new database connection as soon as the database is accessed.  When the 
request completes, the Session should be closed out.   The documentation at 
http://docs.sqlalchemy.org/en/rel_0_8/orm/session.html#session-frequently-asked-questions
 discusses this, and continues the discussion at 
http://docs.sqlalchemy.org/en/rel_0_8/orm/session.html#using-thread-local-scope-with-web-applications
 .


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


Reply via email to