Fix sysrc.managed TypeError in test mode with non-string values#69771
Open
ggiesen wants to merge 1 commit into
Open
Fix sysrc.managed TypeError in test mode with non-string values#69771ggiesen wants to merge 1 commit into
ggiesen wants to merge 1 commit into
Conversation
In test mode, managed() built the preview message via string concatenation (name + " = " + value + ...). When YAML coerces an unquoted value such as YES into a Python bool, this raised TypeError: can only concatenate str (not "bool") to str. Use an f-string so the value is implicitly coerced to its string form. Output is byte-identical for string values. Fixes saltstack#60048
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.
What does this PR do?
Fixes a
TypeErrorraised bysysrc.managedwhen running in test mode (test=True) against a variable whose value is not a string.In test mode,
managed()built the preview change message via string concatenation (name + " = " + value + " will be set."). When YAML coerces an unquoted value such asYES,NO,true,on, oroffinto a Pythonbool(or a bare number into anint),str + bool/str + intraisesTypeError: can only concatenate str (not "bool") to str. This PR switches that line to an f-string so the value is implicitly coerced to its string form. Output is byte-identical for string values, so there is no behaviour change for the normal case.What issues does this PR fix or reference?
Fixes #60048
Previous Behavior
salt '*' state.apply teststate test=Trueraised:New Behavior
The test-mode preview renders correctly:
Merge requirements satisfied
changelog/60048.fixed.md)tests/pytests/unit/states/test_sysrc.py): a direct regression test asserting a bool value no longer raises and rendersvm_enable = True will be set.; an inverse test proving a string value renders identically with and without the fix; and peripheral coverage for an integer value.Commits signed with GPG?: No