Repository navigation
fix(intrinsics): join number and boolean items in Fn::Join - #9412
Open
Shaurya55555 wants to merge 1 commit into
Open
Shaurya55555 wants to merge 1 commit into
Shaurya55555 wants to merge 1 commit into
Conversation
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.
Which issue(s) does this change fix?
None filed. I found it while comparing
IntrinsicResolverwith the newerFn::Joinresolver incfn_language_extensions.Why is this change necessary?
A template that joins a Number parameter, for example
!Join [":", [!Ref Host, !Ref Port]]withPortdeclared asType: Number, Default: 8080, is not resolved byIntrinsicResolver. The parameter default stays an int (SamBaseProvider._get_default_parameter_valuesreturns the YAML value as is), andhandle_fn_joinonly accepts strings, so it raisesInvalidIntrinsicException.SamBaseProvider.get_templateruns the resolver withignore_errors=True, so the wholeFn::Joinis left unresolved. For a function environment variable,EnvironmentVariables._stringify_valuethen turns the leftover dict into an empty string, sosam localruns the function withHOST_PORT="".Fn::Subon the same parameter works ("host:${Port}"giveshost:8080), andFnJoinResolverincfn_language_extensionsalready 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 (
8080to"8080",Trueto"true", asFnJoinResolver._to_stringdoes). Other types (dict, list, None) still raise the same error.Tests:
test_fn_join_items_all_strlistedTrue,Falseand42as invalid list items, which encoded the old behavior, so I removed those three values and kept{}andNone. I addedtest_fn_join_number_and_bool_items(int, float, true, false) andtest_fn_join_ref_to_number_parameter.What side effects does this have?
A
Fn::Joinlist item that is a number or a bool now joins instead of raising, and a template that used to leave theFn::Joinunresolved now resolves it. Lists of strings behave as before. Release-note worthy:sam localandsam buildcan resolve some templates differently, because aFn::Jointhat was left unresolved before now resolves.Mandatory Checklist
PRs will only be reviewed after checklist is complete
make prpasses (not run.black --check -l 120passes on both files)make update-reproducible-reqsif dependencies were changed (no dependencies changed)How I checked it
The resolver files are copies of
developbefore and after this change, with a stub for the one unrelated import (get_template_data, used only byFn::Transform), and the repository'stest_datafolder.{"Fn::Join": [":", ["host", {"Ref": "Port"}]]}withPort=8080is left unresolved before and giveshost:8080after. A literal8080andtruegivehost:8080anda,trueafter. TheFn::Suband string-parameter cases give the same result before and after.test_intrinsic_resolver.pypass after the change. Against the old code, the 5 new tests fail.make pr. I did not runsam localagainst a template; the empty-string step comes from readingEnvironmentVariables._stringify_value.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.