def exception_rollback(func, *args, **kwargs): try: return func(*args, **kwargs) except Exception, e: Session.rollback() raise