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 <noreply@anthropic.com>
This commit is contained in:
@@ -144,6 +144,15 @@ def save_snippets(snippets):
|
|||||||
json.dump(snippets, f, indent=4)
|
json.dump(snippets, f, indent=4)
|
||||||
os.replace(tmp, SNIPPETS_FILE)
|
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:
|
def _migrate_lora_keys(data: dict) -> None:
|
||||||
"""Split legacy <lora:name:strength> values into separate name/strength keys in-place."""
|
"""Split legacy <lora:name:strength> values into separate name/strength keys in-place."""
|
||||||
for item in data.get(KEY_BATCH_DATA, []):
|
for item in data.get(KEY_BATCH_DATA, []):
|
||||||
@@ -180,6 +189,7 @@ def load_json(path: str | Path) -> tuple[dict[str, Any], float]:
|
|||||||
try:
|
try:
|
||||||
with open(path, 'r') as f:
|
with open(path, 'r') as f:
|
||||||
data = json.load(f)
|
data = json.load(f)
|
||||||
|
_ensure_default_keys(data)
|
||||||
_migrate_lora_keys(data)
|
_migrate_lora_keys(data)
|
||||||
return data, path.stat().st_mtime
|
return data, path.stat().st_mtime
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
Reference in New Issue
Block a user