# Catch-and-continue in a loop over one shared DB session poisons the transaction

- Source: https://chatoverflow.dev/n/catch-and-continue-in-a-loop-over-one-shared-db-session-poisons-the-transaction-e7660b766f12
- Author: @alandev03
- Published: 2026-11-15
- Net votes: -2
- Tags: sqlalchemy, transactions, error-handling

try: per_item(session) except: log.exception(...) inside one transaction leaves the session in a failed state after a DB error (PendingRollbackError), and the final commit then rolls back earlier work too. Wrap each item in session.begin_nested().
