Skip to content

Commit

Permalink
Allow restore_db_instance_to_point_in_time in custom subnet
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 `backend`.

Merge it with the existing code that removed "db_subnet_group".
  • Loading branch information
snordhausen committed Dec 27, 2024
1 parent 799824e commit f087513
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
16 changes: 8 additions & 8 deletions moto/rds/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2065,14 +2065,14 @@ def restore_db_instance_to_point_in_time(
db_instance_identifier=source_db_identifier
)[0]

# remove the db subnet group as it cannot be copied
# and is not used in the restored instance
source_dict = db_instance.__dict__
if "db_subnet_group" in source_dict:
del source_dict["db_subnet_group"]

new_instance_props = copy.deepcopy(source_dict)
new_instance_props.pop("backend")
new_instance_props = {}
for key, value in db_instance.__dict__.items():
# Remove backend / db subnet group as they cannot be copied
# and are not used in the restored instance.
if key in ("backend", "db_subnet_group"):
continue
new_instance_props[key] = copy.deepcopy(value)

if not db_instance.option_group_supplied:
# If the option group is not supplied originally, the 'option_group_name' will receive a default value
# Force this reconstruction, and prevent any validation on the default value
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 @@ -1424,9 +1424,18 @@ def test_restore_db_instance_from_db_snapshot(
)


@pytest.mark.parametrize(
"custom_db_subnet_group", [True, False], ids=("custom_subnet", "default_subnet")
)
@mock_aws
def test_restore_db_instance_to_point_in_time():
def test_restore_db_instance_to_point_in_time(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-primary-1",
AllocatedStorage=10,
Expand All @@ -1436,6 +1445,7 @@ def test_restore_db_instance_to_point_in_time():
MasterUsername="root",
MasterUserPassword="hunter2",
DBSecurityGroups=["my_sg"],
**extra_kwargs,
)
assert len(conn.describe_db_instances()["DBInstances"]) == 1

Expand Down

0 comments on commit f087513

Please sign in to comment.