Repository navigation
fix: resolved Fn::FindInMap should not share identity (W1101 false positive) - #4698
Merged
Merged
Conversation
…tensions The AWS::LanguageExtensions transform resolved Fn::FindInMap by returning the value object stored in the Mappings section directly. When more than one location resolved to the same mapping entry, every location shared a single object. That shared identity looked like a YAML alias to rule W1101, producing a false positive on templates that use no aliases, and let a later mutation of one location bleed into the mapping definition. Return a deepcopy of the resolved value so each resolution is an independent object. Fixes aws-cloudformation#4697
The Ref resolution path had the same shared-identity problem as Fn::FindInMap (aws-cloudformation#4697): resolving a Ref to a loop/transform parameter returned the parameter object directly, so two Refs to the same parameter (e.g. under Fn::ForEach) shared one object. When that value is a dict/list it looks like a YAML alias to rule W1101, a false positive. Return a deepcopy of the resolved parameter value from both Ref return paths, matching the Fn::FindInMap fix.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4698 +/- ##
==========================================
+ Coverage 94.65% 94.66% +0.01%
==========================================
Files 434 434
Lines 15561 15561
Branches 3019 3019
==========================================
+ Hits 14729 14731 +2
+ Misses 454 453 -1
+ Partials 378 377 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Adds coverage for the dict-form Ref path where a Ref value resolves to a
parameter name ({"Ref": {"Ref": "Ptr"}}), the one changed line the
existing tests did not exercise (codecov/patch).
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.
Fixes #4697
Problem
W1101(uses YAML alias) fired on templates that contain no YAML aliases whenAWS::LanguageExtensionswas enabled:Root cause
W1101detects YAML aliases by object identity: any dict/list reachable from more than one place in the template is treated as an alias target. TheAWS::LanguageExtensionstransform resolvedFn::FindInMapby returning the value object stored in theMappingssection directly, so bothAandB(and the mapping entry itself) became one shared object. That shared identity looked like an alias, and also let a later mutation of one location bleed into the mapping definition.Fix
Return a
deepcopyof the resolvedFn::FindInMapvalue so each resolution is an independent object.Testing
TestTransformFindInMapDistinctObjectsasserting the two resolutions are equal in value but distinct objects, and distinct from theMappingsentry.W1101.test/unit/rules/suite (1837 tests) and the transform test suite pass.