Skip to content

Error in follow up transactions after trying to insert a user with the same ID #20

@dsmurrell

Description

@dsmurrell

If I try to add another user with the same ID, I get the expected error that comes with trying to violate the unique constraint on ID.

After that however, I get the following error (using both sqlite and postgresql):

site-packages/sqlalchemy/orm/session.py", line 601, in _assert_active raise sa_exc.PendingRollbackError(sqlalchemy.exc.PendingRollbackError: This Session's transaction has been rolled back due to a previous exception during flush. To begin a new transaction with this Session, first issue Session.rollback(). Original exception was: (sqlite3.IntegrityError) UNIQUE constraint failed: user.id

This continues to happen for any transaction until I apply a rollback: session.rollback()

Does something like the following need to be added to the session commits in this library to make sure that this rollback happens automatically?

try:
    <use session>
    session.commit()
except:
    session.rollback()
    raise
finally:
    session.close()  # optional, depends on use case

If not, how can I add code (when using this library) to avoid this happening?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions