On Wed, Apr 28, 2010 at 8:55 AM, Chris Withers <ch...@simplistix.co.uk> wrote: > jason kirtland wrote: >> >> On Wed, Apr 28, 2010 at 7:52 AM, Chris Withers <ch...@simplistix.co.uk> >> wrote: >>> >>> Diana Clarke wrote: >>>> >>>> Finally, we're using pylons and are removing the contextual session in >>>> the >>>> finally clause of the base controller's __call__ method. >>>> >>>> class BaseController(WSGIController): >>>> >>>> def __call__(self, environ, start_response): >>>> try: >>>> ... >>>> finally: >>>> session.remove() >>> >>> Yeah, I'm trying to find out if this .remove() is actually necessary. >> >> .remove() as the final operation in a request ensures that no session >> state leaks from one web request to another. The next request in that >> thread or scoping context will get an entirely fresh session to work >> with. > > Okay, would .close() be equivalent here?
Not really, .close is a Session method. See below. >> If finishing with a .remove() is a big deal in your environment, which >> it seems like it is, you could do a .remove() at the start of the >> request instead. > > What happens if you call .remove() on a virgin session? .remove() is specific to the ScopedSession container. It's not a Session method. It will .close() the session for the current scope, if any (which is effectively a no-op if there is a session but it hasn't performed any work), then remove that session from the scope. The next access to the ScopedSession container will produce a fresh session. -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.