Skip to content

Commit

Permalink
DynamoDB: Make it possible to disable delete protection on a table (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
kiwi-at-billo authored Dec 12, 2024
1 parent 57d0c0e commit ad7de35
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
6 changes: 3 additions & 3 deletions moto/dynamodb/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def create_table(
billing_mode: str,
sse_specification: Optional[Dict[str, Any]],
tags: List[Dict[str, str]],
deletion_protection_enabled: bool,
deletion_protection_enabled: Optional[bool],
) -> Table:
if name in self.tables:
raise ResourceInUseException(f"Table already exists: {name}")
Expand Down Expand Up @@ -182,7 +182,7 @@ def update_table(
throughput: Dict[str, Any],
billing_mode: str,
stream_spec: Dict[str, Any],
deletion_protection_enabled: bool,
deletion_protection_enabled: Optional[bool],
) -> Table:
table = self.get_table(name)
if attr_definitions:
Expand All @@ -195,7 +195,7 @@ def update_table(
table.billing_mode = billing_mode
if stream_spec:
self.update_table_streams(table, stream_spec)
if deletion_protection_enabled:
if deletion_protection_enabled in {True, False}:
table.deletion_protection_enabled = deletion_protection_enabled
return table

Expand Down
17 changes: 17 additions & 0 deletions tests/test_dynamodb/test_dynamodb_update_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,23 @@ def test_update_table_deletion_protection_enabled():
assert table.deletion_protection_enabled


@mock_aws
def test_update_table_deletion_protection_disabled():
conn = boto3.resource("dynamodb", region_name="us-west-2")
table = conn.create_table(
TableName="messages",
KeySchema=[{"AttributeName": "id", "KeyType": "HASH"}],
AttributeDefinitions=[{"AttributeName": "id", "AttributeType": "S"}],
BillingMode="PAY_PER_REQUEST",
DeletionProtectionEnabled=True,
)
assert table.deletion_protection_enabled

table.update(DeletionProtectionEnabled=False)

assert not table.deletion_protection_enabled


@mock_aws
def test_update_table__enable_stream():
conn = boto3.client("dynamodb", region_name="us-east-1")
Expand Down

0 comments on commit ad7de35

Please sign in to comment.