Repository navigation
Fix error handling on prep jid failure (#66457) - #69649
Merged
Merged
Conversation
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.
twangboy
approved these changes
Jul 6, 2026
This branch was previously deployed
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?
Backport of upstream commit
0b6f7e2f213"fix error handling on prep jidfailure" (Matt Phillips, already on 3007.x, 3008.x, master) to 3006.x.
When the returner configured as
master_job_cachefails to load,ClearFuncs._prep_jidreturns{"error": <msg>}(a dict). Before thischange,
ClearFuncs.publishon 3006.x only guardedif jid is None, sothe dict flowed on as the jid and the next
fire_eventblew up withTypeError: expected str, bytes, or bytearray not <class 'dict'>. Theclient 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: postgresand apsycopg2that fails to import),salt '*' test.pingreported'str' object has no attribute 'pop'on the CLI while the master logshowed
TypeError: expected str, bytes, or bytearray not <class 'dict'>inside
fire_event.New Behavior
publishnow treats a dict return from_prep_jidthe same asNoneandpropagates the error load back to
LocalClient.LocalClient.pubcoercesa bare-string payload into
{"error": payload}so the CLI surfaces aPublishErrorwith the returner's real error message instead of anAttributeError.Merge requirements satisfied?
changelog/66457.fixed.md)tests/pytests/unit/test_master.pyregression tests for the master-side and client-side symptoms)
Commits signed with GPG?
No