@contextmanager<EOL>def sessions_scope(local_session, commit=False):
try:<EOL><INDENT>yield local_session<EOL>if commit:<EOL><INDENT>local_session.commit()<EOL>logger.debug("<STR_LIT>")<EOL><DEDENT><DEDENT>except Exception as e:<EOL><INDENT>logger.exception("<STR_LIT>" "<STR_LIT>")<EOL>local_session.rollback()<EOL>raise e<EOL><DEDENT>finally:<EOL><INDENT>local_session.remove()<EOL>logger.debug("<STR_LIT>")<EOL><DEDENT>
Provide a transactional scope around a series of operations.