From 799824efa21c8baad1477731930676112090d071 Mon Sep 17 00:00:00 2001 From: Stefan Nordhausen Date: Fri, 27 Dec 2024 17:04:41 +0100 Subject: [PATCH] Allow modify_db_instance in custom db_subnet_group 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. --- moto/rds/models.py | 2 +- tests/test_rds/test_rds.py | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/moto/rds/models.py b/moto/rds/models.py index 8aae7e86d4aa..9b494c10e04b 100644 --- a/moto/rds/models.py +++ b/moto/rds/models.py @@ -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 ) diff --git a/tests/test_rds/test_rds.py b/tests/test_rds/test_rds.py index 38ddcf4f9157..00bf451867df 100644 --- a/tests/test_rds/test_rds.py +++ b/tests/test_rds/test_rds.py @@ -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, @@ -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