S3Tables: raise TableAlreadyExists instead of building it - #10141
Open
Zuhef wants to merge 1 commit into
Open
Conversation
create_table constructed the exception without raising it, so creating a table whose name already exists was accepted and replaced the existing table instead of returning a ConflictException.
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.
create_tablebuildsTableAlreadyExistswithout raising it, so the duplicate-name guard has no effect:The two
raise NotFoundException(...)guards a few lines above are correct, which is what makes this one stand out.The result is that creating a table with a name that already exists succeeds and replaces the existing table rather than being rejected:
Both
versionTokenandcreatedAtchange, so it is a replacement rather than a no-op, andlist_tablesstill reports one table. Any state the first table had is gone.Adding the
raisemakes it return theConflictExceptionthat the existingTableAlreadyExistsclass was already written for, with its message "A table with an identical name already exists in the namespace.".Added
test_create_table_with_an_existing_name, which fails without the change withFailed: DID NOT RAISE ConflictException. It follows theclient.exceptions.<Name>style already used in this file.tests/test_s3tablespasses (37),ruff formatis clean, mypy reports nothing, andruff check moto/s3tables tests/test_s3tablesfinds the same 4 pre-existing issues before and after my change.I did not verify the exact wording or code that real S3 Tables returns for this. The message and exception class are moto's own, already present in
moto/s3tables/exceptions.py; I only made the existing guard effective.