[sqlalchemy] Re: Old event listeners firing on the wrong session?

2015-02-09 Thread Jonathan Vanasco
I just wanted to suggest another approach that may work, at least as a fallback. When I upload files to Amazon S3 I track the activity in a logging table (via sqlalchemy) that looks a bit like this: id | filename | timestamp_upload_start | upload_status (bool) | timestamp_deleted Before

[sqlalchemy] Re: Old event listeners firing on the wrong session?

2015-02-09 Thread Russ
Problem solved. Michael - you nailed it when you guessed: if you have set an event listener on a single session that is definitely the actual Session object and not the thread local or the scoped_session or anything sa.event.listen was being passed the scoped_session instance, not an

[sqlalchemy] Re: Old event listeners firing on the wrong session?

2015-02-09 Thread Russ
Thanks for the idea, Jonathan! I was actually discussing such a fallback watchdog on #postgresql earlier today. Now that I've been having event troubles and it is highlighting atomicity issues with the db/filesystem split, I'm definitely going to implement such a safety net. I think the

Re: [sqlalchemy] should we wrap sqlalchemy query with a session scope ?

2015-02-09 Thread Michael Bayer
Hao Yan h...@uber.com wrote: Want to ask you guys opinions about this :In the spirit of separating lifecycle of sqlalchemy session from actual operations on db, sqlalchemy suggests the following pattern (http://docs.sqlalchemy.org/en/rel_0_9/orm/session_basics.html ): def

Re: [sqlalchemy] Old event listeners firing on the wrong session?

2015-02-09 Thread Michael Bayer
Russ russandheat...@gmail.com wrote: I have a case where I 'm using threadlocal scoped_sessions and I'm storing a file during a transaction. I want to delete the file if the transaction rolls back for any reason. To handle this I use the event system, something like so: def

[sqlalchemy] Old event listeners firing on the wrong session?

2015-02-09 Thread Russ
I have a case where I 'm using threadlocal scoped_sessions and I'm storing a file during a transaction. I want to delete the file if the transaction rolls back for any reason. To handle this I use the event system, something like so: def write_data(file_path, data): with

[sqlalchemy] should we wrap sqlalchemy query with a session scope ?

2015-02-09 Thread Hao Yan
Want to ask you guys opinions about this :In the spirit of separating lifecycle of sqlalchemy session from actual operations on db, sqlalchemy suggests the following pattern ( http://docs.sqlalchemy.org/en/rel_0_9/orm/session_basics.html ): ### this is a **better** (but not the only) way to do

Re: [sqlalchemy] Old event listeners firing on the wrong session?

2015-02-09 Thread Russ
do you mean to say event.listen(ormSess) here ? Sorry... yes. Poor transcription/reduction. if you have set an event listener on a single session that is definitely the actual Session object and not the thread local or the scoped_session or anything, and that Session is hit by