SQLAlchemy and Alembic 2 · Updating and raw SQL

Roll back on error

Undo pending changes when something fails.

try:
    session.add(User(name="Bad"))
    session.flush()
except Exception:
    session.rollback()
    raise

Official SQLAlchemy and Alembic 2 documentation

More updating and raw sql commands

All updating and raw sql commands · SQLAlchemy and Alembic 2 cheatsheet

Was this page helpful?