mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
24 lines
666 B
Python
24 lines
666 B
Python
from typing import Any
|
|
|
|
from pydantic import BaseModel
|
|
|
|
"""
|
|
We want to exclude null values from objects that make their way to the client.
|
|
|
|
Unfortunately there is no built-in way to do this in pydantic, so we need to override the default
|
|
dict method to do this.
|
|
|
|
From https://github.com/tiangolo/fastapi/discussions/8882#discussioncomment-5154541
|
|
"""
|
|
|
|
|
|
class BaseModelExcludeNull(BaseModel):
|
|
def dict(self, *args, **kwargs) -> dict[str, Any]:
|
|
"""
|
|
Override the default dict method to exclude None values in the response
|
|
"""
|
|
kwargs.pop("exclude_none", None)
|
|
return super().dict(*args, exclude_none=True, **kwargs)
|
|
|
|
pass
|