Skip to content

fix(E8001): report non-string condition names instead of crashing - #4814

Merged
kddejong merged 1 commit into
aws-cloudformation:mainfrom
Varshith-Kali:fix/e8001-non-string-condition-name-4813
Oct 21, 2026
Merged

kddejong merged 1 commit into
aws-cloudformation:mainfrom
Varshith-Kali:fix/e8001-non-string-condition-name-4813

Conversation

@Varshith-Kali

Copy link
Copy Markdown
Contributor

Problem

A Conditions logical ID that parses as a non-string (for example an unquoted YAML integer key) crashes cfn-lint with an unhandled TypeError instead of being reported as an invalid template:

TypeError: name should be a string, not <class 'int'>

The key reaches Conditions.create_from_instance, which calls Symbol(name) during Template.__init__, before any rule runs, so E8001 never gets to validate it. CloudFormation rejects the same template (map keys must be strings).

Root cause

Two gaps:

  1. Conditions.create_from_instance passes every condition name to sympy.Symbol, which requires a string, so a non-string name raises TypeError before rules run.
  2. A propertyNames: {"type": "string"} constraint in conditions.json cannot catch this on its own, because E8001 validates with non-strict type checking (verified: the check is a no-op there).

Fix

  • context/conditions/_conditions.py: skip non-string condition names when building the condition symbol table (E8001 reports them).
  • rules/conditions/Configuration.py (E8001): explicit key-type check yielding 123 is not of type 'string', mirroring the CloudFormation rejection.
  • data/schemas/other/conditions/conditions.json: declare the key constraint via propertyNames.

Tests

  • New regression tests: rule-level (test_condition_non_string_names_rejected) and context-level (test_condition_non_string_names_skipped); both verified red pre-fix (the TypeError) and green post-fix.
  • test/unit/rules/conditions + test/unit/module/context: 155 passed.
  • Full test/unit/rules + test/unit/module: 3021 passed; the 7 failures are pre-existing environment issues (missing pydot/defusedxml etc.), verified identical on pristine upstream main.
  • End-to-end: the issue's repro template now reports E8001 123 is not of type 'string' instead of crashing.

Fixes #4813

A Conditions logical ID that parses as a non-string (for example an unquoted
YAML integer key) crashed cfn-lint with an unhandled TypeError in
Conditions.create_from_instance, before any rule got to run. Skip non-string
names when building the condition symbol table, and report them from E8001
with an explicit key-type check (the schema type validation runs non-strict,
so propertyNames alone cannot catch them). Also declare the key constraint
via propertyNames in the conditions schema.

Fixes aws-cloudformation#4813

Signed-off-by: Varshith Puli <pulivarshit@gmail.com>
@kddejong
kddejong force-pushed the fix/e8001-non-string-condition-name-4813 branch from 7c5ac00 to eac000d Compare October 21, 2026 18:17
@codecov

codecov Bot commented Oct 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.71429% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 94.67%. Comparing base (7e4b262) to head (eac000d).

Files with missing lines Patch % Lines
src/cfnlint/rules/conditions/Configuration.py 80.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4814   +/-   ##
=======================================
  Coverage   94.66%   94.67%           
=======================================
  Files         439      439           
  Lines       15963    15969    +6     
  Branches     3091     3095    +4     
=======================================
+ Hits        15112    15118    +6     
  Misses        468      468           
  Partials      383      383           
Flag Coverage Δ
unittests 94.67% <85.71%> (+<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.

@kddejong
kddejong merged commit dff589f into aws-cloudformation:main Oct 21, 2026
21 of 22 checks passed
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.

Conditions: a non-string (numeric) condition logical ID crashes cfn-lint

2 participants