Skip to content

Fix pgjsonb returner referencing salt.utils.jid without importing it#69043

Open
co-cy wants to merge 1 commit into
saltstack:3006.xfrom
co-cy:pgjsonb-fix-jid-import
Open

Fix pgjsonb returner referencing salt.utils.jid without importing it#69043
co-cy wants to merge 1 commit into
saltstack:3006.xfrom
co-cy:pgjsonb-fix-jid-import

Conversation

@co-cy
Copy link
Copy Markdown

@co-cy co-cy commented May 4, 2026

What does this PR do?

Restores the explicit import salt.utils.jid in
salt/returners/pgjsonb.py. The module uses salt.utils.jid.gen_jid()
in prep_jid() and salt.utils.jid.format_jid_instance() in
get_jids(), but does not import the submodule. Today this works
only because salt.utils.args (transitively pulled in via
salt.utils.data, which the module does import) loads
salt.utils.jid as a side effect.

Adds behavioural unit tests for prep_jid() and get_jids() (none
existed before): the passed_jid pass-through, the default jid
format, and end-to-end formatting of jids-table rows through the
real salt.utils.jid.format_jid_instance().

What issues does this PR fix or reference?

Fixes #69042

Previous Behavior

prep_jid() and get_jids() work only when salt.utils.jid has
been loaded by some other code path before pgjsonb is exercised. In
a process where it has not been (or where a future refactor of
salt.utils.args removes the side effect), both raise:

AttributeError: module 'salt.utils' has no attribute 'jid'

master.py:_prep_jid() only handles KeyError, TypeError, so an
AttributeError there propagates up and prevents job publish.

New Behavior

pgjsonb imports salt.utils.jid explicitly. The functions work
regardless of import order in the surrounding process.

Merge requirements satisfied?

  • Docs (no user-facing change; not required)
  • Changelog — changelog/69042.fixed.md
  • Tests written/updated — see
    tests/pytests/unit/returners/test_pgjsonb.py

Commits signed with GPG?

No.

@co-cy co-cy requested a review from a team as a code owner May 4, 2026 15:53
prep_jid() and get_jids() call salt.utils.jid.gen_jid() and
salt.utils.jid.format_jid_instance() respectively, but the module
removed `import salt.utils.jid` in 3006.x. Both calls work today only
because salt.utils.args (transitively pulled in via salt.utils.data)
imports salt.utils.jid as a side effect. Any refactor of that import
chain silently breaks pgjsonb with:

    AttributeError: module 'salt.utils' has no attribute 'jid'

prep_jid() in particular is called from master.py:_prep_jid() on every
job publish, where the caller only handles KeyError/TypeError, so an
AttributeError there would prevent the master from publishing jobs.

Restore the explicit `import salt.utils.jid` and add behavioural unit
tests for prep_jid() and get_jids() (none existed before): jid format,
passed_jid pass-through, and end-to-end formatting of jids-table rows
through the real salt.utils.jid.format_jid_instance().

Refs: saltstack#69042
@co-cy co-cy force-pushed the pgjsonb-fix-jid-import branch from 1b8f01a to 185b6c6 Compare May 4, 2026 16:04
@dwoz dwoz added the test:full Run the full test suite label May 21, 2026
@dwoz
Copy link
Copy Markdown
Contributor

dwoz commented May 21, 2026

@co-cy conflicts need to be addressed please.

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