fix(civitai): tolerate null creator username in search results

Civitai returns a null username for deleted or anonymous creators. The
field default only applies when the key is absent, so an explicit null
failed str validation and rejected the entire CivitSearchResponse,
dropping every model on that page.

Coerce null or empty usernames to the default in a pre-validator so one
bad creator no longer empties the whole search result.
This commit is contained in:
CalamitousFelicitousness
2026-06-28 02:39:06 +01:00
parent af11b119ea
commit 236d96ef06
+7
View File
@@ -73,6 +73,13 @@ class CivitCreator(BaseModel):
username: str = "Unknown"
image: str | None = None
@validator('username', pre=True)
def coerce_null_username(cls, v): # pylint: disable=no-self-argument
# Deleted/anonymous creators serialize username as null, which failed
# str validation and rejected the entire search response. Fall back to
# the default name instead of dropping the whole page.
return "Unknown" if v in (None, "") else v
class CivitModel(BaseModel):
class Config: