Repository navigation
fix: translate integrity errors from the message upsert - #60
Merged
Merged
Conversation
get_or_create called session.execute directly, so a constraint violation surfaced as SQLAlchemy's IntegrityError instead of advanced-alchemy's ForeignKeyError or DuplicateKeyError, which the API maps to 400 and 409.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
MessagesRepository.get_or_create(from #57) callssession.executedirectly, so a constraint violation reached the caller as SQLAlchemy'sIntegrityError, which the API turns into a 500. The repository's own methods translate these intoForeignKeyError(400) orDuplicateKeyError(409). The upsert now goes throughwrap_sqlalchemy_exception(error_messages=DEFAULT_ERROR_MESSAGE_TEMPLATES, dialect_name="postgresql"), the same asChatsRepository.get_or_create_directin #58.The use case runs its membership check first, so no request can currently reach a foreign-key violation here. The new test therefore calls the repository directly with an unknown
chat_id, and onmainit fails with the untranslated error.Verified locally against Postgres 17 with
ruff format,ruff check,ty check, and the full suite (141 passed, 100% coverage).