Skip to content

Fix error handling on prep jid failure (#66457) - #69649

Merged
dwoz merged 2 commits into
saltstack:3006.xfrom
dwoz:fix/66457-prep-jid-error-handling
Jul 7, 2026
Merged

dwoz merged 2 commits into
saltstack:3006.xfrom
dwoz:fix/66457-prep-jid-error-handling

Conversation

@dwoz

@dwoz dwoz commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Backport of upstream commit 0b6f7e2f213 "fix error handling on prep jid
failure" (Matt Phillips, already on 3007.x, 3008.x, master) to 3006.x.

When the returner configured as master_job_cache fails to load,
ClearFuncs._prep_jid returns {"error": <msg>} (a dict). Before this
change, ClearFuncs.publish on 3006.x only guarded if jid is None, so
the dict flowed on as the jid and the next fire_event blew up with
TypeError: expected str, bytes, or bytearray not <class 'dict'>. The
client side saw the same bug as AttributeError: 'str' object has no attribute 'pop'.

What issues does this PR fix or reference?

Fixes #66457

Previous Behavior

With a broken master_job_cache (e.g. master_job_cache: postgres and a
psycopg2 that fails to import), salt '*' test.ping reported
'str' object has no attribute 'pop' on the CLI while the master log
showed TypeError: expected str, bytes, or bytearray not <class 'dict'>
inside fire_event.

New Behavior

publish now treats a dict return from _prep_jid the same as None and
propagates the error load back to LocalClient. LocalClient.pub coerces
a bare-string payload into {"error": payload} so the CLI surfaces a
PublishError with the returner's real error message instead of an
AttributeError.

Merge requirements satisfied?

  • Docs (no documented behavior change)
  • Changelog (changelog/66457.fixed.md)
  • Tests written/updated (tests/pytests/unit/test_master.py
    regression tests for the master-side and client-side symptoms)

Commits signed with GPG?

No

@dwoz
dwoz requested a review from a team as a code owner July 2, 2026 06:15
@dwoz dwoz added this to the Sulphur v3006.26 milestone Jul 2, 2026
@dwoz dwoz added the test:full Run the full test suite label Jul 2, 2026
dwoz added 2 commits July 3, 2026 15:13
When the returner configured as ``master_job_cache`` fails to load,
``ClearFuncs._prep_jid`` returns ``{"error": <msg>}`` (a dict) rather
than ``None``. ``ClearFuncs.publish`` only checked ``if jid is None``,
so the dict was passed through as the jid and later blew up in
``fire_event`` with:

    TypeError: expected str, bytes, or bytearray not <class 'dict'>

The client-side symptom was ``AttributeError: 'str' object has no
attribute 'pop'`` in ``LocalClient.pub`` when the error came back as
a bare string that was never wrapped in an enc/load envelope.

Treat a dict return from ``_prep_jid`` the same as ``None`` and
propagate the error load back to the caller. On the client, coerce
a str payload into ``{"error": payload}`` so the error surfaces as a
``PublishError`` instead of an ``AttributeError``.

Backport of 0b6f7e2 (already on 3007.x, 3008.x, master) to 3006.x.

Fixes saltstack#66457
MasterACLTestCase and AuthACLTestCase used
``self.clear.mminion.returners = {".prep_jid": lambda x: 1}`` to stub out
the jid returner. ``ClearFuncs._prep_jid`` actually invokes it as
``returners[fstr](nocache=nocache, passed_jid=passed_jid)``, so the
one-positional lambda always raised ``TypeError`` and ``_prep_jid``
silently returned ``{"error": ...}``.

Before the prep-jid error-handling fix, ``publish`` ignored that dict
and passed it through as the jid; ``fire_event`` was mocked in the test
setUp so the tests happily inspected the resulting call. With the new
``isinstance(jid, dict)`` guard in ``publish``, ``fire_event`` is no
longer called when ``_prep_jid`` errors, and eight tests broke on
``TypeError: 'NoneType' object is not subscriptable`` when reading
``fire_event_mock.call_args[0][0]``.

Give the stub the real signature (``nocache=False, passed_jid=None``)
and a valid string jid so ``publish`` reaches ``fire_event`` as the
tests expect.

This branch was previously deployed

1 inactive deployment
ci — 464173f0 Deployed Jul 4, 2026 by dwoz via Build Onedir Packages / macOS (arm64) #25219
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