Hi, FYI - I spent quite a while staring at this and it seems sqlalchemy doesn't always update all the data in it's objects when a select is issued, resulting in potentially stale data. In order to force it to repopulate the data you need to:
res = Session.query(abc).populate_existing().first() This does however mean that any state changed before in that object will be overwritten. Damian On Dec 23, 12:39 am, Damian <[email protected]> wrote: > Hi, > > I've been trying to debug an issue i've been having with pylons in > mod_wsgi running with multiple threads and processes in daemon mode > and I've come to a point where I think my scoped_session's are > possibly being shared across threads. At least thats the only > explanation I can find, barring postgres being broken. > > Problem: > So, I have a query that does a postgres style Select with lockmode > update in sqlalchemy, it then modifies the data, creates a new > sqlalchemy object, adds it to the session and commits it. Quite > frequently it looks like no locking occured at all. Ie, the new > sqlalchemy object (insert) is a history record of what happened and I > can see that two, in some cases 3 or even 4 history records have the > same data. > > Setup: > The sqlalchemy model uses reflection, and therefore requires > init_environment in environment.py to set up the Session and engine. > init_environenment calls the following method: > > def init_model(engine): > """Call me before using any of the tables or classes in the > model""" > > sm = sessionmaker(autoflush=True, autocommit=False, bind=engine) > > meta.engine = engine > meta.Session = scoped_session(sm) > > My question is, is it possible that meta.Session is somehow not thread > local? > Should a new scoped_session be created for each call in the > BaseController class in __call__? > I know scoped_session is said to be thread safe, so I'm not sure what > I'm doing wrong. > > From the command line when i run multiple paster shell instances, the > postgres with update locks hold. > > Am I missing something? Any help would be very welcome. > > Thanks, > Damian -- 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.
