Skip to content

fix(sqlalchemy): atomic decorator must preserve logic exceptions #571

Closed

Description

@HosseinNejatiJavaremi

Problem: the atomic decorator is supposed to be a unit-of-work boundary, but _handle_db_exception converts every non-SQLAlchemy exception to InternalError. A swallowed default nested failure also raises DatabaseTransactionError with no cause, so the caller loses the original logic error type and details.

Fix: map only SQLAlchemyError to Database*Error; re-raise BaseError and every other exception unchanged. Store the first exception from a nested savepoint=False failure and re-raise it at the outer boundary after the rollback, instead of raising DatabaseTransactionError. DatabaseTransactionError stays for genuine SQLAlchemy transaction failures. Savepoint mode already re-raises the inner error to its caller.

Checklist

  • map only SQLAlchemy failures; re-raise logic exceptions unchanged
  • store and re-raise the original nested failure at the outer boundary
  • update atomic tests and docs
  • release notes for 5.28.0

Activity

  1. github-actions commented on Nov 2, 2026

    @github-actions
    Contributor

    Merged #572: fix(sqlalchemy): preserve logic exceptions in atomic blocks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:mysqlmysql adapter packagearea:postgrespostgres adapter packagearea:sqlitesqlite adapter packagearea:starrocksstarrocks adapter packagebugSomething isn't workingpriority:highNeeds attention soon

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions