Need
The SDK uses two JSON libraries interchangeably with no documented rule for
which to use when. Across infrahub_sdk/, ~16 modules use ujson (the apparent
house standard) and ~7 use stdlib json; playback.py and utils.py import
both. This makes the codebase harder to reason about and creates a latent
exception-handling hazard: ujson raises its own ujson.JSONDecodeError and
stdlib raises json.JSONDecodeError, and the two do not catch each other. Today
every decode/except pair happens to be internally consistent, but nothing
enforces that — a future ujson.loads guarded by except json.JSONDecodeError
(or the reverse) would silently fail to catch a malformed-input error.
Context
Concrete smells found while surveying usage:
playback.py serializes with json.dumps (:52) but reads the recorded
files back with ujson.load (:57). This works today (both speak valid JSON)
but the asymmetry is a smell and imports both libraries in one module.
utils.py also imports both json and ujson.
- The decode/except pairs are currently consistent everywhere
(e.g. pytest_plugin items pair ujson.loads with except ujson.JSONDecodeError;
infrahub_filters.py and parsers.py pair stdlib json.loads with
except json.JSONDecodeError), so this is a maintainability/consistency
concern rather than an active bug.
Note: an earlier framing suspected utils.py:97 (decode_json) of catching the
wrong exception for a ujson failure — that turned out to be a false alarm. That
line decodes via httpx's response.json() (stdlib-backed), so its
except json.decoder.JSONDecodeError is correct.
Affects: Python SDK.
Need
The SDK uses two JSON libraries interchangeably with no documented rule for
which to use when. Across
infrahub_sdk/, ~16 modules useujson(the apparenthouse standard) and ~7 use stdlib
json;playback.pyandutils.pyimportboth. This makes the codebase harder to reason about and creates a latent
exception-handling hazard:
ujsonraises its ownujson.JSONDecodeErrorandstdlib raises
json.JSONDecodeError, and the two do not catch each other. Todayevery decode/except pair happens to be internally consistent, but nothing
enforces that — a future
ujson.loadsguarded byexcept json.JSONDecodeError(or the reverse) would silently fail to catch a malformed-input error.
Context
Concrete smells found while surveying usage:
playback.pyserializes withjson.dumps(:52) but reads the recordedfiles back with
ujson.load(:57). This works today (both speak valid JSON)but the asymmetry is a smell and imports both libraries in one module.
utils.pyalso imports bothjsonandujson.(e.g. pytest_plugin items pair
ujson.loadswithexcept ujson.JSONDecodeError;infrahub_filters.pyandparsers.pypair stdlibjson.loadswithexcept json.JSONDecodeError), so this is a maintainability/consistencyconcern rather than an active bug.
Note: an earlier framing suspected
utils.py:97(decode_json) of catching thewrong exception for a
ujsonfailure — that turned out to be a false alarm. Thatline decodes via httpx's
response.json()(stdlib-backed), so itsexcept json.decoder.JSONDecodeErroris correct.Affects: Python SDK.