Normalize external pair metadata shape

This commit is contained in:
2026-06-27 14:31:21 +02:00
parent d724e4518a
commit 95dc8939b6
2 changed files with 62 additions and 19 deletions
+15 -19
View File
@@ -100,21 +100,25 @@ def sanitize_metadata_row_text(row: dict[str, Any], *, active_trigger: str = "")
return row
def _sync_pair_root_row_field(pair: dict[str, Any], row_key: str, root_key: str, row_field: str) -> None:
row = pair.get(row_key)
if not isinstance(row, dict):
return
if root_key in pair:
row[row_field] = pair.get(root_key)
elif row_field in row:
pair[root_key] = row.get(row_field)
def synchronize_pair_row_outputs(pair: dict[str, Any]) -> dict[str, Any]:
mapping = (
("softcore_row", "softcore_prompt", "softcore_caption", "softcore_negative_prompt"),
("hardcore_row", "hardcore_prompt", "hardcore_caption", "hardcore_negative_prompt"),
)
for row_key, prompt_key, caption_key, negative_key in mapping:
row = pair.get(row_key)
if not isinstance(row, dict):
continue
if prompt_key in pair:
row["prompt"] = pair.get(prompt_key, "")
if caption_key in pair:
row["caption"] = pair.get(caption_key, "")
if negative_key in pair:
row["negative_prompt"] = pair.get(negative_key, "")
_sync_pair_root_row_field(pair, row_key, prompt_key, "prompt")
_sync_pair_root_row_field(pair, row_key, caption_key, "caption")
_sync_pair_root_row_field(pair, row_key, negative_key, "negative_prompt")
return pair
@@ -132,12 +136,8 @@ def synchronize_pair_side_metadata(pair: dict[str, Any]) -> dict[str, Any]:
),
}
for row_key, keys in side_keys.items():
row = pair.get(row_key)
if not isinstance(row, dict):
continue
for key in keys:
if key in pair:
row[key] = pair.get(key)
_sync_pair_root_row_field(pair, row_key, key, key)
return pair
@@ -155,12 +155,8 @@ def synchronize_pair_camera_metadata(pair: dict[str, Any]) -> dict[str, Any]:
),
}
for row_key, keys in mapping.items():
row = pair.get(row_key)
if not isinstance(row, dict):
continue
for source_key, target_key in keys:
if source_key in pair:
row[target_key] = pair.get(source_key)
_sync_pair_root_row_field(pair, row_key, source_key, target_key)
return pair