On Sep 18, 2012, at 11:38 AM, Derek Litz wrote: > A session when closed, commited, or rolled back, releases the database > connection it acquired from the pool. The session can grab a new connection > later on as needed. Also, many objects a session can create have a reference > to this session, and the session could be used elsewhere. This leads to the > potential of doing database access where one would have thought no database > access was going on, even if I'm clearly not re-using the session object > anywhere else directly. > > ie. I call session.close() before passing my data to a template engine, but > one of the objects was a query object (by mistake), which when iterated over > will query the database while rendering the template. > > Is there a standard way I could stop the session object from grabbing another > connection to the database and throw an exception instead? If not I'd be > open to non-standard ways as well :)
You can reset the ".bind" on the Session to None, but this assumes that you aren't using "bound metadata". As far as non-standard, I've never tried this but if you manually "deactivate" the transaction, should work: session.transaction._deactivate() This can certainly be a public API at some point if it works for you. -- 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 sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.