def new_funct(*args, **kwargs): if not isgeneratorfunction(function): raise IDDSException( 'stream_session decorator should be used only with generator. Use read_session instead.' ) if not kwargs.get('session'): session = get_session() try: kwargs['session'] = session for row in function(*args, **kwargs): yield row except TimeoutError as error: print(error) session.rollback() # pylint: disable=maybe-no-member raise DatabaseException(str(error)) except DatabaseError as error: print(error) session.rollback() # pylint: disable=maybe-no-member raise DatabaseException(str(error)) except: # noqa: B901 session.rollback() # pylint: disable=maybe-no-member raise finally: session.remove() else: try: for row in function(*args, **kwargs): yield row except: # noqa: B901 raise
def new_funct(*args, **kwargs): if isgeneratorfunction(function): raise IDDSException( 'read_session decorator should not be used with generator. Use stream_session instead.' ) if not kwargs.get('session'): session = get_session() try: kwargs['session'] = session return function(*args, **kwargs) except TimeoutError as error: session.rollback() # pylint: disable=maybe-no-member raise DatabaseException(str(error)) except DatabaseError as error: session.rollback() # pylint: disable=maybe-no-member raise DatabaseException(str(error)) except: # noqa: B901 session.rollback() # pylint: disable=maybe-no-member raise finally: session.remove() try: return function(*args, **kwargs) except: # noqa: B901 raise
def new_funct(*args, **kwargs): if not kwargs.get('session'): session = get_session() try: kwargs['session'] = session result = function(*args, **kwargs) session.commit() # pylint: disable=maybe-no-member except TimeoutError as error: print(error) session.rollback() # pylint: disable=maybe-no-member raise DatabaseException(str(error)) except DatabaseError as error: print(error) session.rollback() # pylint: disable=maybe-no-member raise DatabaseException(str(error)) except: # noqa: B901 session.rollback() # pylint: disable=maybe-no-member raise finally: session.remove() # pylint: disable=maybe-no-member else: result = function(*args, **kwargs) return result