<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Jun 4, 2008, at 12:02 PM, Hermann Himmelbauer wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>Hi,<br>Regarding to the discussion some days ago with the SQLAlchemy Zope3 <br>integration, I still have problems with retrieving the session. I currently <br>use a utility for the engine, which seems to work well.<br><br>However, for retrieving the session, I tried to use the following pattern <br>(many thanks to Michael Bayer, btw.):<br><br>-------- database module -----------<br>SASession = scoped_session(sessionmaker(<br> &nbsp;&nbsp;&nbsp;transactional = True,<br> &nbsp;&nbsp;&nbsp;autoflush = True,<br> &nbsp;&nbsp;&nbsp;extension = ZopeTransactionExtension()))<br><br>def getSASession():<br> &nbsp;&nbsp;&nbsp;SASession.remove()<br> &nbsp;&nbsp;&nbsp;engine = getUtility(ISAEngineUtility).getEngine()<br> &nbsp;&nbsp;&nbsp;s = SASession()<br> &nbsp;&nbsp;&nbsp;s.bind = engine<br> &nbsp;&nbsp;&nbsp;return s<br>--------------------------------------------<br><br>In my application, I then use getSASession() to retrieve my session.<br><br>However, what I think is not that beautiful is the "s.bind = engine" part. Are <br>there any suggestions how to improve this?<br></div></blockquote></div><br><div><br></div><div>FTR, my suggestion here is to configure/tear down sessions upon request boundaries, as described in&nbsp;<a href="http://www.sqlalchemy.org/docs/04/session.html%23unitofwork_contextual_lifespan">http://www.sqlalchemy.org/docs/04/session.html#unitofwork_contextual_lifespan</a>&nbsp;. &nbsp;</div></body></html>