mirror of
https://github.com/vladmandic/automatic
synced 2026-09-19 09:14:35 +02:00
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:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user