fix: gallery CLI image serialization crashes on a non-string prompt (#1598)

This commit is contained in:
Afonso Coutinho
2026-06-03 00:36:51 +01:00
committed by GitHub
parent 0283216e67
commit 667c663668
2 changed files with 56 additions and 1 deletions

View File

@@ -30,11 +30,19 @@ except ModuleNotFoundError as e:
sys.exit(2)
def _preview_text(value, limit: int = 200) -> str:
"""Truncated preview tolerant of non-string values. A gallery row whose
``prompt`` is a non-string would crash ``(value or "")[:200]`` with a
TypeError; coerce non-strings to ""."""
text = value if isinstance(value, str) else ""
return text[:limit]
def _serialize_image(i: "GalleryImage") -> dict:
return {
"id": i.id,
"filename": i.filename,
"prompt": (i.prompt or "")[:200],
"prompt": _preview_text(i.prompt),
"model": i.model or "",
"size": i.size or "",
"tags": i.tags or "",