> hmm, is that because your model objects themselves are controlling the > scope of the transaction ? That's another pattern I don't really > recommend... > > As I mentioned, I'm using Flask-SQLAlchemy, where I have a global db instance of the SQLAlchemy class, which holds the engine, current session, session factory, etc.
All models have high-level methods for save, delete, revert, etc, which use the global db.session. This isn't an issue for the web part of the application, because Flask creates a new session for each request context, but the workers are outside the request context and the tasks use the db.session directly, either through the models or by themselves. The session created by Flask on the request is a subclass of the scoped session with some signal handling extras. So, your solution works, but to implement that without changing everything, I have to replicate whatever the high-level methods do using that local session created when the task is called. I think it might be possible to create a request context on each task call, so everyone will have a fresh session on the global db.session, as if it were a web request, but I'll have to go into Flask internals to figure how to do that. > > Would this all be solved if I just use READ COMMITTED transaction > isolation? > > > maybe? If the problem is really just exactly those rows needing to be > visible. But the long running "dormant" transaction thing is still kind of > an antipattern that will generally have negative effects. > Well... I do realize that, but unfortunately it's an application with many bad design decisions, but it has to work somehow until we can afford fixing everything. Thanks a lot! --- Pedro Werneck -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@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.