From 6c3d62e7d7591ac52aad83047b14ea85cbbabc28 Mon Sep 17 00:00:00 2001 From: SAY-5 Date: Mon, 11 May 2026 23:00:06 -0700 Subject: [PATCH] fix: import salt.utils.jid explicitly in pgjsonb returner (#69042) --- changelog/69042.fixed.md | 1 + salt/returners/pgjsonb.py | 1 + tests/pytests/unit/returners/test_pgjsonb.py | 20 ++++++++++++++++++++ 3 files changed, 22 insertions(+) create mode 100644 changelog/69042.fixed.md diff --git a/changelog/69042.fixed.md b/changelog/69042.fixed.md new file mode 100644 index 000000000000..0588042ee11a --- /dev/null +++ b/changelog/69042.fixed.md @@ -0,0 +1 @@ +Restore explicit ``import salt.utils.jid`` in the ``pgjsonb`` returner so that ``prep_jid`` and ``get_jids`` no longer rely on the import being pulled in transitively. Without the explicit import, any change to the import chain raised ``AttributeError: module 'salt.utils' has no attribute 'jid'`` and prevented the master from publishing jobs when ``master_job_cache: pgjsonb`` was in use. diff --git a/salt/returners/pgjsonb.py b/salt/returners/pgjsonb.py index fb043ef1d7ae..1afda19aa8a9 100644 --- a/salt/returners/pgjsonb.py +++ b/salt/returners/pgjsonb.py @@ -167,6 +167,7 @@ import salt.exceptions import salt.returners import salt.utils.data +import salt.utils.jid import salt.utils.job try: diff --git a/tests/pytests/unit/returners/test_pgjsonb.py b/tests/pytests/unit/returners/test_pgjsonb.py index df68fc16ffa8..ee5e90a75ad4 100644 --- a/tests/pytests/unit/returners/test_pgjsonb.py +++ b/tests/pytests/unit/returners/test_pgjsonb.py @@ -317,3 +317,23 @@ def test_event_return_logs_on_database_error_without_raising(caplog): "failed to store" in r.message and "3 event" in r.message for r in caplog.records ) + + +def test_module_imports_salt_utils_jid_explicitly(): + """ + ``prep_jid`` and ``get_jids`` reference ``salt.utils.jid.gen_jid`` and + ``salt.utils.jid.format_jid_instance``. Prior to the fix the module did + not import ``salt.utils.jid`` itself and only worked because another + salt module transitively loaded it. Refactoring the import chain + silently broke the returner with + ``AttributeError: module 'salt.utils' has no attribute 'jid'``. + + This regression test asserts that the module-level import is present + so future refactors can no longer drop it. + """ + import salt.utils.jid as utils_jid + + # The module's globals must expose the same ``salt.utils.jid`` object + # so that ``salt.utils.jid.gen_jid`` and ``salt.utils.jid.format_jid_instance`` + # always resolve regardless of the order in which other salt modules load. + assert pgjsonb.salt.utils.jid is utils_jid