From c880c16865ba31fe9bd645fc92f7f1fbbe49e93c Mon Sep 17 00:00:00 2001 From: Ethanfel Date: Wed, 18 Mar 2026 23:24:34 +0100 Subject: [PATCH] Backfill missing default keys into sequences on JSON load Ensures all sequences have required keys like mode, cfg, etc. from DEFAULTS via setdefault so they persist on next save. Co-Authored-By: Claude Opus 4.6 --- utils.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/utils.py b/utils.py index d200b80..d46a205 100644 --- a/utils.py +++ b/utils.py @@ -144,6 +144,15 @@ def save_snippets(snippets): json.dump(snippets, f, indent=4) os.replace(tmp, SNIPPETS_FILE) +def _ensure_default_keys(data: dict) -> None: + """Ensure all sequences have required keys from DEFAULTS.""" + for item in data.get(KEY_BATCH_DATA, []): + if not isinstance(item, dict): + continue + for k, v in DEFAULTS.items(): + item.setdefault(k, v) + + def _migrate_lora_keys(data: dict) -> None: """Split legacy values into separate name/strength keys in-place.""" for item in data.get(KEY_BATCH_DATA, []): @@ -180,6 +189,7 @@ def load_json(path: str | Path) -> tuple[dict[str, Any], float]: try: with open(path, 'r') as f: data = json.load(f) + _ensure_default_keys(data) _migrate_lora_keys(data) return data, path.stat().st_mtime except Exception as e: