Skip to content

Commit

Permalink
test: assert delete_table raises on version_token mismatch
Browse files Browse the repository at this point in the history
  • Loading branch information
felixscherz committed Jan 20, 2025
1 parent e5ef686 commit a77ca1d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
4 changes: 3 additions & 1 deletion moto/s3tables/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ def list_tables(
return tables, next_continuation_token

def delete_table(
self, table_bucket_arn: str, namespace: str, name: str, version_token: str
self, table_bucket_arn: str, namespace: str, name: str, version_token: Optional[str] = None
) -> None:
bucket = self.table_buckets.get(table_bucket_arn)
if (
Expand All @@ -418,6 +418,8 @@ def delete_table(

ns = bucket.namespaces[namespace]
table = ns.tables[name]
if version_token and not version_token == table.version_token:
raise VersionTokenMismatch()
from moto.s3.models import s3_backends

s3_backends[self.account_id][self.partition].delete_table_storage_bucket(
Expand Down
3 changes: 1 addition & 2 deletions moto/s3tables/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,7 @@ def delete_table(self) -> TYPE_RESPONSE:
_, table_bucket_arn, namespace, name = self.raw_path.lstrip("/").split("/")
table_bucket_arn = unquote(table_bucket_arn)
params = self._get_params()
version_token = params.get("versionToken", "")
# TODO: if versinToken not supplied, raise exception
version_token = params.get("versionToken")
self.s3tables_backend.delete_table(
table_bucket_arn=table_bucket_arn,
namespace=namespace,
Expand Down
15 changes: 15 additions & 0 deletions tests/test_s3tables/test_s3tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,21 @@ def test_delete_table_deletes_underlying_table_storage():
s3.head_bucket(Bucket=bucket_name)


@mock_aws
def test_delete_table_fails_on_version_token_mismatch():
client = boto3.client("s3tables", region_name="us-east-2")
arn = client.create_table_bucket(name="foo")["arn"]
client.create_namespace(tableBucketARN=arn, namespace=["bar"])
resp = client.create_table(
tableBucketARN=arn, namespace="bar", name="baz", format="ICEBERG"
)
token = resp["versionToken"]


with pytest.raises(client.exceptions.ConflictException):
client.delete_table(tableBucketARN=arn, namespace="bar", name="baz", versionToken=f"{token}-foo")


@mock_aws
def test_get_table_metadata_location():
client = boto3.client("s3tables", region_name="us-east-2")
Expand Down

0 comments on commit a77ca1d

Please sign in to comment.