Skip to content

[Bug]: pgjsonb returner uses salt.utils.jid without importing it (latent AttributeError) #69042

@co-cy

Description

@co-cy

What happened?

Description

The salt.returners.pgjsonb module references salt.utils.jid.gen_jid()
in prep_jid() and salt.utils.jid.format_jid_instance() in
get_jids(), but does not import salt.utils.jid itself. Both calls
currently work only as a side effect: salt.utils.args (transitively
pulled in via salt.utils.data, which the module does import) loads
salt.utils.jid. Any refactor of that import chain silently breaks
pgjsonb with AttributeError: module 'salt.utils' has no attribute 'jid'.

prep_jid() is called from master.py:_prep_jid() on every job
publish; that caller only handles KeyError, TypeError, so an
AttributeError there propagates up and prevents the master from
publishing jobs.

This was introduced in 3006.x when the explicit import salt.utils.jid
was dropped during the migration from salt.utils.jid to
salt.utils.data / salt.utils.job for decode() and
get_keep_jobs_seconds(). The two salt.utils.jid.* call sites were
overlooked. The bug is present on 3006.x, 3007.x, 3008.x and
mastergit diff between any of those branches for this file
shows no change to the relevant lines.

Setup

  • on-prem machine
  • classic packaging
  • onedir packaging

Any deployment that uses master_job_cache: pgjsonb or invokes
salt-run jobs.list_jobs (which calls get_jids()) is at risk; the
visible failure mode depends on whether salt.utils.args happens to
be loaded before salt.returners.pgjsonb in the running process.

Steps to Reproduce the behavior

In a clean Python interpreter:

import sys
import importlib

import salt.returners.pgjsonb as pgjsonb
import salt.utils

# Detach salt.utils.jid from the package and from sys.modules to
# simulate an environment where it was not transitively loaded.
delattr(salt.utils, "jid")
sys.modules.pop("salt.utils.jid", None)

# Reload pgjsonb so its import block re-executes in the cleaned env.
importlib.reload(pgjsonb)

pgjsonb.__opts__ = {}
pgjsonb.prep_jid()
# AttributeError: module 'salt.utils' has no attribute 'jid'

The same AttributeError is reachable through get_jids() because
it calls salt.utils.jid.format_jid_instance().

Expected behavior

prep_jid() and get_jids() succeed regardless of which other
modules have been imported beforehand in the process.

Additional context

The module already imports salt.utils.data and salt.utils.job
explicitly. The minimal fix is to add import salt.utils.jid between
them. Trace of how salt.utils.jid enters sys.modules today, when
it does:

salt.utils.data → salt.utils.args → salt.utils.jid

If salt.utils.args ever stops importing salt.utils.jid at module
load time (e.g. lazy-import refactor), pgjsonb breaks silently in
production.

Type of salt install

Official deb

Major version

3006.x, 3007.x

What supported OS are you seeing the problem on? Can select multiple. (If bug appears on an unsupported OS, please open a GitHub Discussion instead)

debian-11, debian-12

salt --versions-report output

salt --versions-report
Salt Version:
          Salt: 3007.13

Python Version:
        Python: 3.10.19 (main, Feb  5 2026, 07:05:38) [GCC 11.2.0]

Dependency Versions:
          cffi: 2.0.0
      cherrypy: unknown
  cryptography: 42.0.5
      dateutil: 2.8.2
     docker-py: Not Installed
         gitdb: Not Installed
     gitpython: Not Installed
        Jinja2: 3.1.6
       libgit2: 1.9.1
  looseversion: 1.3.0
      M2Crypto: Not Installed
          Mako: Not Installed
       msgpack: 1.0.7
  msgpack-pure: Not Installed
  mysql-python: Not Installed
     packaging: 24.0
     pycparser: 2.21
      pycrypto: Not Installed
  pycryptodome: 3.19.1
        pygit2: 1.18.2
  python-gnupg: 0.5.2
        PyYAML: 6.0.1
         PyZMQ: 25.1.2
        relenv: 0.22.3
         smmap: Not Installed
       timelib: 0.3.0
       Tornado: 6.5.4
           ZMQ: 4.3.4

Salt Extensions:
 saltext.vault: 1.5.0

Salt Package Information:
  Package Type: onedir

System Versions:
          dist: debian 12.13 bookworm
        locale: utf-8
       machine: x86_64
       release: 6.12.73+deb12-amd64
        system: Linux
       version: Debian GNU/Linux 12.13 bookworm

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugbroken, incorrect, or confusing behaviorneeds-triage

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions