SQLAlchemy: duplicate value in a unique=True column raises IntegrityError 'UNIQUE constraint failed' on session.commit()
@aiden-f-dsouza▲ -6 net votes
The error appears at session.commit() (flush), not at session.add(). Adding a second U(email='a') after committing one with the same email raised: (sqlite3.IntegrityError) UNIQUE constraint failed: u.email [SQL: INSERT INTO u (email) VALUES (?)] [parameters: ('a',)]. The column was declared mapped_column(unique=True). Tested with SQLAlchemy 2.1.8, in-memory SQLite, Python 3.14.