Skip to content

Keep the test mode result and do not include force_mod_watch in state results (follow-up to #68960) - #70972

Open
mitar wants to merge 2 commits into
saltstack:masterfrom
mitar:fix-68960
Open

mitar wants to merge 2 commits into
saltstack:masterfrom
mitar:fix-68960

Conversation

@mitar

@mitar mitar commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes two bugs in the force_mod_watch opt-in which #68960 added. #68960 is only on master, so no release has them yet.

  1. Test mode result. When a watching state returns force_mod_watch: True and its normal run made changes, the state system runs mod_watch as well and merges both results with bool(ret.get("result")) and bool(mod_ret.get("result", True)). In test mode both runs return None to report that they would make changes, so the merged result became False and a dry run reported the state as failed. The merge now keeps all three values: False if either run failed, otherwise None if either run would make changes, otherwise True.
  2. force_mod_watch in results. call_chunk removed the key only in the branch where a watched state had changes. In every other case (no watch requisite, a watched state without changes, a result of mod_watch which replaces the normal one) the key remained in the state's result and in the job return. state.single and state.low call State.call directly, so they kept it too. The key is now removed at the end of call_chunk on every path, and in state.single and state.low.

Each fix is a separate commit with its own test.

What issues does this PR fix or reference?

Follow-up to #68960 (issue #68958).

Previous Behavior

With this SLS:

trigger:
  test.succeed_with_changes

watcher:
  test.succeed_with_changes:
    - force_mod_watch: True
    - watch:
      - test: trigger
  • state.apply with test=True reports watcher with result: False, although nothing failed.
  • The result of watcher without the watch requisite, and the result of state.single test.succeed_with_changes name=example force_mod_watch=True, contain force_mod_watch: True.

New Behavior

  • state.apply with test=True reports watcher with result: None, and the comment of mod_watch ("Watch statement fired.") is still merged in.
  • No state result contains force_mod_watch.

Merge requirements satisfied?

[NOTICE] Bug fixes or features added to Salt require tests.

  • Docs: doc/ref/states/requisites.rst now says how the combined result is computed, including test mode.
  • Changelog: both commits extend changelog/68958.fixed.md, the entry of Allow watching states to opt-in to mod_watch when normal run had changes #68960, so that the unreleased entry describes the final behavior. The changelog check accepts only one <issue>.<type>.md file per issue and type, and these bugs have no issue of their own. I can add a separate entry if you prefer one.
  • Tests written/updated: two functional tests in tests/pytests/functional/modules/state/requisites/test_watch.py. Each fails without its fix. All requisite core tests (101), tests/pytests/unit/modules/state (71), tests/pytests/unit/state (128) and the other tests/pytests/functional/modules/state tests (139) pass.

Commits signed with GPG?

Yes

When a watching state returns force_mod_watch and its normal run made
changes, the state system runs mod_watch as well and merges both
results. The merge converted both results with bool(), so in test mode,
where both runs return None to report that they would make changes, the
merged result became False and the state was reported as failed.

Merge the results so that False wins over None, and None wins over
True.

Follow-up to saltstack#68960.
force_mod_watch only tells the state system whether to run mod_watch,
but call_chunk removed it from the result only when a watched state had
changes. In every other case, such as a state without a watch requisite,
a watched state without changes, or a result of mod_watch itself, the key
remained in the state's result. state.single and state.low call
State.call directly, so they kept the key as well.

Remove the key at the end of call_chunk on every path, and in
state.single and state.low.

Follow-up to saltstack#68960.
@mitar
mitar requested a review from a team as a code owner November 27, 2026 13:26
@dwoz dwoz added the test:full Run the full test suite label Nov 27, 2026
mitar added a commit to mitar/saltext-dockermod that referenced this pull request Nov 28, 2026
The functional test read force_mod_watch from the state's result, which
works only while Salt leaves the key in results. saltstack/salt#70972
removes it from every result, so the test now checks the change which
the flag depends on: connecting a network reports only network changes,
and the container keeps its Id and its start time. The unit tests check
the flag itself.

This branch was previously deployed

1 inactive deployment
ci — 990e6399 Deployed Nov 27, 2026 by dwoz via Build Onedir Packages / DEB (arm64) #29744
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.

2 participants