Skip to content

Commit 8490c08

Browse files
authored
Always copy profile (#274)
1 parent b85d718 commit 8490c08

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

samtranslator/model/connector_profiles/profile.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import copy
12
import json
23
import os
34
import re
@@ -10,7 +11,9 @@
1011

1112

1213
def get_profile(source_type: str, dest_type: str):
13-
return PROFILE["Permissions"].get(source_type, {}).get(dest_type)
14+
profile = PROFILE["Permissions"].get(source_type, {}).get(dest_type)
15+
# Ensure not passing a mutable shared variable
16+
return copy.deepcopy(profile)
1417

1518

1619
def verify_profile_variables_replaced(obj: Any) -> None:

tests/model/connector_profiles/test_profile.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
from parameterized import parameterized
44

5-
from samtranslator.model.connector_profiles.profile import profile_replace, verify_profile_variables_replaced
5+
from samtranslator.model.connector_profiles.profile import (
6+
get_profile,
7+
profile_replace,
8+
verify_profile_variables_replaced,
9+
)
610

711

812
class TestProfile(TestCase):
@@ -235,3 +239,9 @@ def test_verify_not_replaced(self, profile, error_includes):
235239
with self.assertRaises(ValueError) as ctx:
236240
verify_profile_variables_replaced(profile)
237241
self.assertIn(error_includes, str(ctx.exception))
242+
243+
def test_get_profile_copied(self):
244+
d1 = get_profile("AWS::Lambda::Function", "AWS::DynamoDB::Table")
245+
d1["Type"] = "overridden"
246+
d2 = get_profile("AWS::Lambda::Function", "AWS::DynamoDB::Table")
247+
self.assertNotEqual(d1, d2)

0 commit comments

Comments
 (0)