mirror of
https://github.com/jhd3197/ServerKit.git
synced 2026-12-01 20:55:16 +09:00
~60 call sites across 24 model files now ride _json_read with each site's exact default preserved; 34 classes newly adopt the mixin (registry contract test expanded to 36). Reverses the old 'bare sites stay raising' ruling: a corrupt row degrades to its default instead of 500ing every serializing endpoint (docstring updated). Ratchet: json.loads( appears only in json_column_mixin.py. Known pre-existing: test_host_inventory enumerate_filesystems failures on this machine (verified via clean-tree stash rerun). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
37 lines
1.3 KiB
Python
37 lines
1.3 KiB
Python
"""Plan 77 B4 ratchet: models parse JSON through ONE door.
|
|
|
|
Every hand-rolled ``json.loads`` in a model file is a bypass of
|
|
``JsonColumnMixin._json_read`` — a place where a corrupt row raises and
|
|
500s every endpoint that serializes the model instead of degrading to the
|
|
accessor's default. Plan 77 B4 converted the last of them; this ratchet
|
|
keeps the count at zero. If this test fails, use ``self._json_read(...)``
|
|
(inherit ``JsonColumnMixin`` first in the bases) instead of ``json.loads``.
|
|
"""
|
|
|
|
from pathlib import Path
|
|
|
|
MODELS_DIR = Path(__file__).resolve().parents[1] / 'app' / 'models'
|
|
|
|
# The mixin is the one place allowed to call json.loads.
|
|
ALLOWED = {'json_column_mixin.py'}
|
|
|
|
|
|
def test_no_model_file_hand_rolls_json_loads():
|
|
offenders = {}
|
|
for path in sorted(MODELS_DIR.glob('*.py')):
|
|
if path.name in ALLOWED:
|
|
continue
|
|
lines = [
|
|
f'{path.name}:{lineno}'
|
|
for lineno, line in enumerate(
|
|
path.read_text(encoding='utf-8').splitlines(), start=1
|
|
)
|
|
if 'json.loads(' in line
|
|
]
|
|
if lines:
|
|
offenders[path.name] = lines
|
|
assert not offenders, (
|
|
'json.loads( in model files outside json_column_mixin.py — '
|
|
f'use self._json_read instead: {offenders}'
|
|
)
|