Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DynamoDB: Make it possible to disable delete protection on a table #8391

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading