fix(cfn-lang-ext): preserve template-time intrinsics with unresolved param Refs in PARTIAL mode (#9004)#9010
Merged
Conversation
Hoist the helper duplicated in four resolvers (fn_find_in_map, fn_join, fn_select, fn_base64) up to samcli/lib/cfn_language_extensions/utils.py next to PSEUDO_PARAMETERS. Each resolver now imports the shared helper and drops its private copy. Adds focused unit tests in test_utils.py covering parameter Refs, pseudo-parameter Refs, resource Refs, Fn::GetAtt, multi-key dicts, non-string Ref targets, and contexts without a parsed_template.
9829353 to
e475c99
Compare
roger-zhangg
approved these changes
May 14, 2026
reedham-aws
approved these changes
May 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue(s) does this change fix?
#9004
Why is this change necessary?
SAM CLI 1.160.0 introduced the in-tree CloudFormation Language Extensions resolver. Four template-time intrinsic resolvers (
Fn::FindInMap,Fn::Join,Fn::Select,Fn::Base64) raiseInvalidTemplateException("... layout is incorrect")when an argument resolves to an unresolved{"Ref": <param>}dict.This breaks
sam buildfor any template usingAWS::LanguageExtensionswith!Refto a parameter that has noDefaultand no override — a regression from 1.159.1.The user-reported repro:
sam build→Error: Fn::FindInMap layout is incorrect.How does it address the issue?
In
ResolutionMode.PARTIAL(the modesam buildalways uses), preserve the call when an argument resolved to{"Ref": <name>}and<name>is a declared template parameter or a pseudo-parameter — exactly the references CloudFormation will resolve at deploy time. Resource refs and other intrinsics (Fn::GetAtt, etc.) continue to raise: those genuinely can't be inputs to template-time intrinsics at any stage, matching Kotlin compatibility behavior tested undertests/unit/lib/cfn_language_extensions/compatibility/test_kotlin_compatibility.py.The shared discriminator
is_unresolved_param_or_pseudo_ref(value, context)lives insamcli/lib/cfn_language_extensions/utils.pyand is consumed by all four fixed resolvers.Files changed:
samcli/lib/cfn_language_extensions/resolvers/fn_find_in_map.py— preserve when any of map_name / top_key / second_key is an unresolved param Ref (root cause of Bug:sam buildfails with "Fn::FindInMap layout is incorrect" when usingAWS::LanguageExtensionswith an unresolved!Refparameter as a map key (regression in 1.160.0) #9004)samcli/lib/cfn_language_extensions/resolvers/fn_join.py— preserve when delimiter or list is an unresolved param Ref; widenedresolve()return type toAnysamcli/lib/cfn_language_extensions/resolvers/fn_select.py— preserve when index is an unresolved param Ref (source-list path was already correct)samcli/lib/cfn_language_extensions/resolvers/fn_base64.py— preserve when arg is an unresolved param Ref; widenedresolve()return type toAnysamcli/lib/cfn_language_extensions/utils.py— new shared helperis_unresolved_param_or_pseudo_refWhat side effects does this change have?
None expected.
Fn::GetAttas inputs to these template-time intrinsics still raiseInvalidTemplateException(fnFindInMapWithUnsupportedFunctionFnRef,fnFindInMapWithUnsupportedFunctionFnGetAtt,fnFindInMapWithUnsupportedFunctionInMapName).Fn::GetAttraises); end-to-end test drivingprocess_templatewith the issue Bug:sam buildfails with "Fn::FindInMap layout is incorrect" when usingAWS::LanguageExtensionswith an unresolved!Refparameter as a map key (regression in 1.160.0) #9004 repro template; focused unit tests for the new shared helper. 1685 unit tests pass intests/unit/lib/cfn_language_extensions/.Mandatory Checklist
process_templatemake prpasses (make lintclean for changed files; only pre-existing unrelated mypy errors remain ondevelop)make update-reproducible-reqsif dependencies were changed — N/A, no dependency changesBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.