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 1df833d66e04..1c4a01d1291a 100644 --- a/salt/returners/pgjsonb.py +++ b/salt/returners/pgjsonb.py @@ -174,6 +174,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 d0c2bf83a5cd..a151872f284d 100644 --- a/tests/pytests/unit/returners/test_pgjsonb.py +++ b/tests/pytests/unit/returners/test_pgjsonb.py @@ -79,3 +79,23 @@ def test_save_load_with_bytes(): with patch.object(psycopg2.extras, "Json") as json_mock: pgjsonb.save_load(load["jid"], load) json_mock.assert_called_with(decoded_load) + + +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