Skip to content

Fix sysrc.managed TypeError in test mode with non-string values#69771

Open
ggiesen wants to merge 1 commit into
saltstack:3006.xfrom
ggiesen:fix-60048
Open

Fix sysrc.managed TypeError in test mode with non-string values#69771
ggiesen wants to merge 1 commit into
saltstack:3006.xfrom
ggiesen:fix-60048

Conversation

@ggiesen

@ggiesen ggiesen commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes a TypeError raised by sysrc.managed when 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 as YES, NO, true, on, or off into a Python bool (or a bare number into an int), str + bool/str + int raises TypeError: 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

syssrc_vm_enable:
  sysrc.managed:
    - name: vm_enable
    - value: YES

salt '*' state.apply teststate test=True raised:

TypeError: can only concatenate str (not "bool") to str

New Behavior

The test-mode preview renders correctly:

Changes:
    new:
        vm_enable = True will be set.
    old:
        None

Merge requirements satisfied

  • Docs (n/a - no documented behaviour change)
  • Changelog entry added (changelog/60048.fixed.md)
  • Tests written and described (in tests/pytests/unit/states/test_sysrc.py): a direct regression test asserting a bool value no longer raises and renders vm_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

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
@ggiesen ggiesen requested a review from a team as a code owner July 10, 2026 17:56
@charzl charzl self-assigned this Jul 10, 2026
@dwoz dwoz added the test:full Run the full test suite label Jul 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test:full Run the full test suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants