-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix(intrinsics): only resolve the selected Fn::If branch #9134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
EPNOS
wants to merge
6
commits into
aws:develop
Choose a base branch
from
EPNOS:fix/4510-lazy-fn-if-resolution
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d4c07ac
fix(intrinsics): resolve only the selected Fn::If branch
EPNOS 16c70d0
fix(intrinsics): forward ignore_errors to Fn::GetAtt symbol resolution
EPNOS e16ec5b
test(intrinsics): add integration coverage for Fn::If with unresolvab…
EPNOS 0a7b27d
Merge branch 'develop' into fix/4510-lazy-fn-if-resolution
EPNOS 88ffaea
fix(intrinsics): stop forwarding ignore_errors into Fn::GetAtt symbol…
EPNOS 57b4fbd
Merge branch 'fix/4510-lazy-fn-if-resolution' of https://github.com/E…
EPNOS File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[BUG] handle_fn_if can now return
None, which it could never do before, and at least one downstream consumer is not null-safe.Before this change, a branch containing
!Ref AWS::NoValuewas pre-resolved toNoneby the outerintrinsic_property_resolver(intrinsic_value, ...)call, and the subsequentresolve(arguments[1|2])hit theif intrinsic is None: raise InvalidIntrinsicExceptionguard at the top ofintrinsic_property_resolver. SoFn::Ifalways raised, and withignore_errors=Truethe enclosing dict loop left the property as the raw{"Fn::If": [...]}dict.Now the selected branch is resolved directly, so
!Ref AWS::NoValuereachesIntrinsicsSymbolTable.handle_pseudo_no_value()andNoneis returned and assigned as the property value (the generic dict branch doessanitized_dict[sanitized_key] = sanitized_valwith no None filtering).Concrete failure — the common "conditionally omit a property" idiom:
When
UseLayersis false,Properties["Layers"]becomesNone. Insamcli/lib/providers/sam_function_provider.py:265,resource_properties.get("Layers", [])returnsNone(the default only applies when the key is absent), and_parse_layer_infothen doesfor layer in list_of_layers→TypeError: 'NoneType' object is not iterable, an unhandled traceback instead of a domain error.Note the element-level form
Layers: [!If [Cond, !Ref MyLayer, !Ref "AWS::NoValue"]]is fine — it yields[None]and_parse_layer_infoskips unrecognized entries. Only the whole-property form breaks, and that is exactly one of the scenarios this PR sets out to fix, so it is worth closing here rather than leaving it as a newly reachable crash.Two options:
AWS::NoValuesemantics by dropping keys whose resolved value isNonein the generic dict branch ofintrinsic_property_resolver. This is the semantically correct fix but has wider blast radius, so it needs its own tests.resource_properties.get("Layers") or []in both call sites insam_function_provider.py.Either way, please add a unit test covering an
Fn::Ifwhose selected branch is!Ref AWS::NoValue— the four new tests only cover unresolvableFn::GetAttin the unselected branch, so this path is currently untested.Note on the previous review comment: the handle_fn_getatt change that forwarded ignore_errors into resolve_symbols is no longer in the diff, and test_template_ignore_errors_leaves_unresolvable_layer_getatt_as_dict was added as a guard for the nested-stack layer behavior. That finding is resolved and I did not re-raise it. The PR description still describes the handle_fn_getatt change, so it is now out of date.