Skip to content

Commit

Permalink
Allow modify_db_instance in custom db_subnet_group
Browse files Browse the repository at this point in the history
Previously, this failed with
    TypeError: cannot pickle 'generator' object
when the code tried to deepcopy the `database.db_subnet_group`.

But a deepcopy isn't needed in this case, the subsequent
    database.master_user_secret_status = ...
will not affect the shallow copy. Also, the copy is only needed
to render the response template.
  • Loading branch information
snordhausen committed Dec 27, 2024
1 parent 19b69b0 commit 799824e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion moto/rds/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2005,7 +2005,7 @@ def modify_db_instance(
"You must specify apply immediately when rotating the master user password.",
)
database.update(db_kwargs)
initial_state = copy.deepcopy(database)
initial_state = copy.copy(database)
database.master_user_secret_status = (
"active" # already set the final state in the background
)
Expand Down
12 changes: 11 additions & 1 deletion tests/test_rds/test_rds.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,9 +551,18 @@ def test_describe_non_existent_database():
conn.describe_db_instances(DBInstanceIdentifier="not-a-db")


@pytest.mark.parametrize(
"custom_db_subnet_group", [True, False], ids=("custom_subnet", "default_subnet")
)
@mock_aws
def test_modify_db_instance():
def test_modify_db_instance(custom_db_subnet_group: bool):
conn = boto3.client("rds", region_name=DEFAULT_REGION)

if custom_db_subnet_group:
extra_kwargs = {"DBSubnetGroupName": create_db_subnet_group()}
else:
extra_kwargs = {}

conn.create_db_instance(
DBInstanceIdentifier="db-id",
AllocatedStorage=10,
Expand All @@ -563,6 +572,7 @@ def test_modify_db_instance():
MasterUserPassword="hunter2",
Port=1234,
DBSecurityGroups=["my_sg"],
**extra_kwargs,
)
inst = conn.describe_db_instances(DBInstanceIdentifier="db-id")["DBInstances"][0]
assert inst["AllocatedStorage"] == 10
Expand Down

0 comments on commit 799824e

Please sign in to comment.