Skip to content

fix(intrinsics): join number and boolean items in Fn::Join - #9412

Open
Shaurya55555 wants to merge 1 commit into
aws:developfrom
Shaurya55555:fix/fn-join-number-items
Open

Shaurya55555 wants to merge 1 commit into
aws:developfrom
Shaurya55555:fix/fn-join-number-items

Conversation

@Shaurya55555

Copy link
Copy Markdown
Contributor

Which issue(s) does this change fix?

None filed. I found it while comparing IntrinsicResolver with the newer Fn::Join resolver in cfn_language_extensions.

Why is this change necessary?

A template that joins a Number parameter, for example !Join [":", [!Ref Host, !Ref Port]] with Port declared as Type: Number, Default: 8080, is not resolved by IntrinsicResolver. The parameter default stays an int (SamBaseProvider._get_default_parameter_values returns the YAML value as is), and handle_fn_join only accepts strings, so it raises InvalidIntrinsicException. SamBaseProvider.get_template runs the resolver with ignore_errors=True, so the whole Fn::Join is left unresolved. For a function environment variable, EnvironmentVariables._stringify_value then turns the leftover dict into an empty string, so sam local runs the function with HOST_PORT="". Fn::Sub on the same parameter works ("host:${Port}" gives host:8080), and FnJoinResolver in cfn_language_extensions already converts numbers and booleans to strings.

How does it address the issue?

The resolved list items that are an int, a float or a bool are converted to their string form before the existing type check (8080 to "8080", True to "true", as FnJoinResolver._to_string does). Other types (dict, list, None) still raise the same error.

Tests: test_fn_join_items_all_str listed True, False and 42 as invalid list items, which encoded the old behavior, so I removed those three values and kept {} and None. I added test_fn_join_number_and_bool_items (int, float, true, false) and test_fn_join_ref_to_number_parameter.

What side effects does this have?

A Fn::Join list item that is a number or a bool now joins instead of raising, and a template that used to leave the Fn::Join unresolved now resolves it. Lists of strings behave as before. Release-note worthy: sam local and sam build can resolve some templates differently, because a Fn::Join that was left unresolved before now resolves.

Mandatory Checklist

PRs will only be reviewed after checklist is complete

  • Review the generative AI contribution guidelines (I used an AI assistant, Claude Code, to find and draft this. I reviewed the change and can answer questions about it.)
  • Add input/output type hints to new functions/methods (the new private static helper is typed)
  • Write design document if needed (not needed)
  • Write/update unit tests
  • Write/update integration tests (not needed for this change)
  • Write/update functional tests if needed (not needed)
  • make pr passes (not run. black --check -l 120 passes on both files)
  • make update-reproducible-reqs if dependencies were changed (no dependencies changed)
  • Write documentation (not needed)

How I checked it

The resolver files are copies of develop before and after this change, with a stub for the one unrelated import (get_template_data, used only by Fn::Transform), and the repository's test_data folder.

  • {"Fn::Join": [":", ["host", {"Ref": "Port"}]]} with Port=8080 is left unresolved before and gives host:8080 after. A literal 8080 and true give host:8080 and a,true after. The Fn::Sub and string-parameter cases give the same result before and after.
  • All 293 tests in test_intrinsic_resolver.py pass after the change. Against the old code, the 5 new tests fail.
  • Not run: the full unit suite, integration tests and make pr. I did not run sam local against a template; the empty-string step comes from reading EnvironmentVariables._stringify_value.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@Shaurya55555
Shaurya55555 requested a review from a team as a code owner November 7, 2026 09:03
@github-actions github-actions Bot added pr/external stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. labels Nov 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr/external stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant