Skip to content

fix: resolved Fn::FindInMap should not share identity (W1101 false positive) - #4698

Merged
kddejong merged 3 commits into
aws-cloudformation:mainfrom
kddejong:fix/issue/4697
Sep 10, 2026
Merged

kddejong merged 3 commits into
aws-cloudformation:mainfrom
kddejong:fix/issue/4697

Conversation

@kddejong

Copy link
Copy Markdown
Contributor

Fixes #4697

Problem

W1101 (uses YAML alias) fired on templates that contain no YAML aliases when AWS::LanguageExtensions was enabled:

Transform: AWS::LanguageExtensions
Mappings:
  FooMap:
    TopKey:
      SecondKey: [0]
Resources:
  NoOp:
    Type: AWS::CloudFormation::WaitConditionHandle
    Metadata:
      A: !FindInMap [FooMap, TopKey, SecondKey]
      B: !FindInMap [FooMap, TopKey, SecondKey]

Root cause

W1101 detects YAML aliases by object identity: any dict/list reachable from more than one place in the template is treated as an alias target. The AWS::LanguageExtensions transform resolved Fn::FindInMap by returning the value object stored in the Mappings section directly, so both A and B (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 deepcopy of the resolved Fn::FindInMap value so each resolution is an independent object.

Testing

  • New regression test TestTransformFindInMapDistinctObjects asserting the two resolutions are equal in value but distinct objects, and distinct from the Mappings entry.
  • Verified the reported template lints clean and a genuine YAML alias still warns W1101.
  • Full test/unit/rules/ suite (1837 tests) and the transform test suite pass.

…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

codecov Bot commented Sep 10, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.66%. Comparing base (e239754) to head (84f9a6a).
⚠️ Report is 1 commits behind head on main.

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     
Flag Coverage Δ
unittests 94.66% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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).
@kddejong
kddejong merged commit fb6da9d into aws-cloudformation:main Sep 10, 2026
21 checks passed
@kddejong
kddejong deleted the fix/issue/4697 branch September 10, 2026 17:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

W1101 false positive

1 participant