Created
April 30, 2024 03:22
-
-
Save daaniam/1389ecfb8aeac6c04926e50f037e68dc to your computer and use it in GitHub Desktop.
SQLAlchemy asyncpg
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Just a note where to find original asyncpg exception object wrapped by SQLAlchemy | |
""" | |
try: | |
created_record = await db.scalar(insert(Model).values(**data_in.model_dump()).returning(Model)) | |
except IntegrityError as err: | |
if isinstance(err.orig.__cause__, UniqueViolationError): | |
raise RecordAlreadyExists() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment