lavkach3
1from enum import Enum2from functools import wraps3
4from core.db import session5
6
7class Propagation(Enum):8REQUIRED = "required"9REQUIRED_NEW = "required_new"10
11
12class Transactional:13def __init__(self, propagation: Propagation = Propagation.REQUIRED):14self.propagation = propagation15
16def __call__(self, function):17@wraps(function)18async def decorator(*args, **kwargs):19try:20result = await function(*args, **kwargs)21await session.commit()22except Exception as e:23await session.rollback()24raise e25return result26return decorator27