Skip to content

fix(rules): don't crash when a resource or output condition can never be true - #4786

Merged
kddejong merged 1 commit into
aws-cloudformation:mainfrom
Varshith-Kali:varshith/cfn-lint-4785-unsatisfiable-condition
Oct 21, 2026
Merged

kddejong merged 1 commit into
aws-cloudformation:mainfrom
Varshith-Kali:varshith/cfn-lint-4785-unsatisfiable-condition

Conversation

@Varshith-Kali

Copy link
Copy Markdown
Contributor

Fixes #4785

Root cause

Properties.validate (E3002 family) pins the resource's own Condition to True through context.conditions.evolve(...) before validating its properties, and outputs/Value.py (E6101) does the same for outputs. When that condition can never be true (for example X and not X over two identical condition bodies), evolve raises Unsatisfiable and nothing catches it. The cfnLint keyword catch-all then reports it as an E3001 Exception "When setting condition '...' to True" raised while validating 'cfnLint' finding, and the rest of that resource's (or output's) validation is skipped, hiding real findings.

Fix

Catch Unsatisfiable at both pins and continue validation without the impossible pin. This is consistent with how cfn-lint already handles a lone statically false condition used directly on a resource: the resource is still validated (E3002 fires on its bad properties) instead of crashing. It follows the existing convention used by the other conditions.evolve call sites (_resolvers_cfn.py, rules/functions/If.py, template.py, ...), which all catch Unsatisfiable.

Tests

  • Reproduced all four templates from the issue before the fix: templates A and B reported the E3001 exception; template C reported E3002 only on Control while Gated got the crash; template D reported the output-side exception. After the fix: no exceptions; template C reports E3002 on both Control and Gated (the issue's expected behavior); templates A, B, D report only the expected W8003s. A lone named always-false condition crashed the same way before the fix and is also fixed.
  • Added regression tests: test_validate_with_unsatisfiable_condition (resources/properties) and test_output_value_with_unsatisfiable_condition (outputs). Both fail with Unsatisfiable raised before the fix and pass after.
  • Full unit suite: 2930 passed; 8 failures in test/unit/module are pre-existing environment issues (missing pydot/defusedxml modules, provider-schema content drift), confirmed identical on pristine upstream/main. Ruff check and format clean.

Caveats

  • When the condition pin is unsatisfiable, the resource/output is now validated without any condition facts. CloudFormation itself would skip a false-gated resource entirely, but this matches cfn-lint's existing handling of the statically-false-condition case, which is what the issue asked for.
  • Value.py pins any truthy Condition value (not just strings); that pre-existing behavior is unchanged.

…on can never be true

Properties.validate pinned the resource's own condition to True through
context.conditions.evolve(), and outputs/Value.py did the same for
outputs. When that condition is unsatisfiable (for example X and not X
over two identical condition bodies), evolve raised Unsatisfiable and
nothing caught it, so the cfnLint keyword catch-all reported it as an
E3001 Exception raised while validating finding and the rest of that
resource's validation was skipped.

Catch Unsatisfiable at both pins and continue validation without the
impossible pin, consistent with how a lone statically false condition
used directly already behaves (E3002 on the gated resource, no crash).

Adds regression tests for the resource shape and the output shape (both
fail with Unsatisfiable before the fix).

Fixes aws-cloudformation#4785

Signed-off-by: Varshith Puli <pulivarshit@gmail.com>
@kddejong
kddejong force-pushed the varshith/cfn-lint-4785-unsatisfiable-condition branch from 5abfdf3 to 8c818e1 Compare October 20, 2026 23:58
@codecov

codecov Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.70%. Comparing base (16acc6f) to head (8c818e1).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4786   +/-   ##
=======================================
  Coverage   94.70%   94.70%           
=======================================
  Files         439      439           
  Lines       15895    15905   +10     
  Branches     3078     3078           
=======================================
+ Hits        15053    15063   +10     
  Misses        459      459           
  Partials      383      383           
Flag Coverage Δ
unittests 94.70% <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.

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.

E3001/E6001: unhandled Unsatisfiable when a resource or output Condition can never be true

2 participants