Skip to content

Commit ba850af

Browse files
committed
fix: extract parameter defaults independently for each template in code change detection
Use each template's own Parameters section to extract defaults, so expansion produces correct results even if parameter definitions changed between the current and deployed template versions.
1 parent f8d5d09 commit ba850af

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

samcli/lib/sync/infra_sync_executor.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -586,18 +586,24 @@ def _detect_foreach_code_changes(
586586
from samcli.lib.cfn_language_extensions.sam_integration import expand_language_extensions
587587

588588
try:
589-
# Extract parameter default values from the template so Ref-based
590-
# ForEach collections (e.g. {"Ref": "ServiceNames"}) can be resolved.
591-
param_values = {}
589+
# Extract parameter default values from each template independently
590+
# so Ref-based ForEach collections can be resolved correctly even if
591+
# parameter definitions changed between deployments.
592+
current_params = {}
592593
for param_name, param_def in current_template.get("Parameters", {}).items():
593594
if isinstance(param_def, dict) and "Default" in param_def:
594-
param_values[param_name] = param_def["Default"]
595+
current_params[param_name] = param_def["Default"]
596+
597+
deployed_params = {}
598+
for param_name, param_def in last_deployed_template.get("Parameters", {}).items():
599+
if isinstance(param_def, dict) and "Default" in param_def:
600+
deployed_params[param_name] = param_def["Default"]
595601

596602
current_expanded = expand_language_extensions(
597-
current_template, parameter_values=param_values
603+
current_template, parameter_values=current_params
598604
).expanded_template
599605
deployed_expanded = expand_language_extensions(
600-
last_deployed_template, parameter_values=param_values
606+
last_deployed_template, parameter_values=deployed_params
601607
).expanded_template
602608
except Exception as e:
603609
LOG.warning(

0 commit comments

Comments
 (0)