Skip to content

Commit e314697

Browse files
committed
refactor(cfn-lang-ext): use jmespath for build_context artifact copy
1 parent 2c298a2 commit e314697

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

samcli/commands/build/build_context.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -919,6 +919,7 @@ def _copy_artifact_paths(self, original_resource: Dict, modified_resource: Dict)
919919
The modified resource with updated artifact paths
920920
"""
921921
from samcli.lib.cfn_language_extensions.models import PACKAGEABLE_RESOURCE_ARTIFACT_PROPERTIES
922+
from samcli.lib.package.language_extensions_packaging import _get_prop_value, _set_prop_value
922923

923924
original_props = original_resource.get("Properties", {})
924925
modified_props = modified_resource.get("Properties", {})
@@ -929,8 +930,9 @@ def _copy_artifact_paths(self, original_resource: Dict, modified_resource: Dict)
929930
return
930931

931932
for prop_name in prop_names:
932-
if prop_name in modified_props:
933-
original_props[prop_name] = modified_props[prop_name]
933+
value = _get_prop_value(modified_props, prop_name)
934+
if value is not None:
935+
_set_prop_value(original_props, prop_name, value)
934936

935937
def _gen_success_msg(self, artifacts_dir: str, output_template_path: str, is_default_build_dir: bool) -> str:
936938
"""

tests/unit/commands/buildcmd/test_build_context_language_extensions.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,21 @@ def test_no_matching_property_no_copy(self):
9191
ctx._copy_artifact_paths(original, modified)
9292
self.assertNotIn("CodeUri", original["Properties"])
9393

94+
def test_glue_job_dotted_path(self):
95+
"""Regression: dotted property path (Command.ScriptLocation) must be copied."""
96+
ctx = self._make_context()
97+
original = {
98+
"Type": "AWS::Glue::Job",
99+
"Properties": {"Command": {"Name": "glueetl", "ScriptLocation": "./script.py"}},
100+
}
101+
modified = {
102+
"Type": "AWS::Glue::Job",
103+
"Properties": {"Command": {"Name": "glueetl", "ScriptLocation": "s3://b/k.py"}},
104+
}
105+
ctx._copy_artifact_paths(original, modified)
106+
self.assertEqual(original["Properties"]["Command"]["ScriptLocation"], "s3://b/k.py")
107+
self.assertEqual(original["Properties"]["Command"]["Name"], "glueetl")
108+
94109

95110
class TestGetTemplateForOutputForEachExploration(TestCase):
96111
"""

0 commit comments

Comments
 (0)