add note about discriminated union and Body() issue; blackified

This commit is contained in:
Lincoln Stein
2023-11-12 16:50:05 -05:00
parent ef8dcf5fae
commit 8afe517204
11 changed files with 41 additions and 18 deletions

View File

@ -268,7 +268,14 @@ AnyModelConfig = Union[
T2IConfig,
]
# Preferred alternative is a discriminated Union, but it breaks FastAPI when applied to a route.
AnyModelConfigValidator = TypeAdapter(AnyModelConfig)
# IMPLEMENTATION NOTE:
# The preferred alternative to the above is a discriminated Union as shown
# below. However, it breaks FastAPI when used as the input Body parameter in a route.
# This is a known issue. Please see:
# https://github.com/tiangolo/fastapi/discussions/9761 and
# https://github.com/tiangolo/fastapi/discussions/9287
# AnyModelConfig = Annotated[
# Union[
# _MainModelConfig,
@ -284,8 +291,6 @@ AnyModelConfig = Union[
# Field(discriminator="type"),
# ]
AnyModelConfigValidator = TypeAdapter(AnyModelConfig)
class ModelConfigFactory(object):
"""Class for parsing config dicts into StableDiffusion Config obects."""