code: def _session(self):
          
          # Taken from the session docs.
          session = self._session_maker()
          try:
              yield session
              session.commit()
          except:
              session.rollback()
              raise
          finally:
              session.close()
docs: Provide a transactional scope around a series of operations.