]> git.decadent.org.uk Git - dak.git/commit
daklib/ls.py: manage our own database session
authorAnsgar Burchardt <ansgar@debian.org>
Mon, 15 Jun 2015 18:53:02 +0000 (20:53 +0200)
committerAnsgar Burchardt <ansgar@debian.org>
Mon, 15 Jun 2015 18:53:02 +0000 (20:53 +0200)
commit3eeb70441392e4f506ef2a9370cc0fec8672ad1e
treeb0b599622a74f4f0ccfa93ba718427fdd1847154
parent1eb5ee70e67aeaee9e51fc02a9f4f5fab9577517
daklib/ls.py: manage our own database session

session_wrapper gets confused by generators: let "f" be a generator
making use of a database session:

    def wrapped_f():
      session = DBConn().session()
      try:
        return f(session)
      finally:
        session.close()

    for item in wrapped_f():
      do_something(item)

will leak database sessions as the implementation of "f" will only be
invoked from the for-loop. However at this time the "finally" block
closing the session has already run. SQLAlchemy will helpfully reopen
the session, but it will not be closed in the end.
daklib/ls.py