Scope SQLAlchemy 2.0 Sessions with Session.begin() for safe transactional writes
Scope SQLAlchemy 2.0 Sessions with Session.begin() to get atomic commits, avoid stale data and DetachedInstanceError. Use declarative mapping with Mapped and mapped_column and 2.0 select() queries.