[Bug]: pgjsonb returner uses salt.utils.jid without importing it (latent AttributeError)
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 15.7k
- Forks
- 5.6k
- Avg merge
- 2d 44m
- Merged PRs (30d)
- 80
Description
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
master — git 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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Open salt/returners/pgjsonb.py and inspect prep_jid() and get_jids(), then run the clean-interpreter reproduction from the issue to verify the latent import dependency. Done means both calls work without salt.utils.jid being loaded transitively, while existing pgjsonb behavior remains intact.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- postgresql, python
- Domain
- database
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 86/100