Skip to content

Commit

Permalink
RDS Fix bug that causes second PIT restore to fail (#7991)
Browse files Browse the repository at this point in the history
  • Loading branch information
egrif committed Aug 16, 2024
1 parent 3827cce commit 88405fc
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
3 changes: 2 additions & 1 deletion moto/rds/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1881,7 +1881,8 @@ def restore_db_instance_to_point_in_time(
# remove the db subnet group as it cannot be copied
# and is not used in the restored instance
source_dict = db_instance.__dict__
del source_dict["db_subnet_group"]
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")
Expand Down
28 changes: 28 additions & 0 deletions tests/test_rds/test_rds.py
Original file line number Diff line number Diff line change
Expand Up @@ -1262,6 +1262,34 @@ def test_restore_db_instance_to_point_in_time():
)
== 1
)
# ensure another pit restore can be made
new_instance = conn.restore_db_instance_to_point_in_time(
SourceDBInstanceIdentifier="db-primary-1",
TargetDBInstanceIdentifier="db-restore-2",
)["DBInstance"]
assert new_instance["DBInstanceIdentifier"] == "db-restore-2"
assert new_instance["DBInstanceClass"] == "db.m1.small"
assert new_instance["StorageType"] == "gp2"
assert new_instance["Engine"] == "postgres"
assert new_instance["DBName"] == "staging-postgres"
assert new_instance["DBParameterGroups"][0]["DBParameterGroupName"] == (
"default.postgres9.3"
)
assert new_instance["DBSecurityGroups"] == [
{"DBSecurityGroupName": "my_sg", "Status": "active"}
]
assert new_instance["Endpoint"]["Port"] == 5432

# Verify it exists
assert len(conn.describe_db_instances()["DBInstances"]) == 3
assert (
len(
conn.describe_db_instances(DBInstanceIdentifier="db-restore-2")[
"DBInstances"
]
)
== 1
)


@mock_aws
Expand Down

0 comments on commit 88405fc

Please sign in to comment.