On Oct 25, 2007, at 12:03 PM, Yannick Gingras wrote:
> > > Greetings Alchemists, > I'm using Alchemy for a Pylons application and I just migrated to > 0.4. > My application has a read only mode and even though I do all the > relevant checks all over the place, I know I'm going to forget a > critical spot one of there days so I used to do: > > def abort_ro(): > log.error(...) > abort(403) > > if c.site_readonly: > model.ctx.current.flush = abort_ro > > I'd like to do something like this with Alchemy 0.4 but I'm a bit > lost. I use a scoped session like this: > > db_sess = scoped_session(sessionmaker(autoflush=True, > transactional=True, > bind=config > ['pylons.g'].sa_engine)) > > So the session object is reused all over the place and overwriting one > of its methods is not a good idea. What would be my best option to > implement readonly mode? the design of scoped_session is not much different from SessionContext. if you were setting ctx.current.flush to something for every new session, the approach here would be the same (Session ().flush = abort_ro). if you were only setting ctx.current.flush to abort_ro() at the module level, then your 0.3 approach wasn't working either (since 'current' is a functional property) ;). --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---