From 32d85fb89607ee3901a2f4492c8364e7bcaf9779 Mon Sep 17 00:00:00 2001 From: -LAN- Date: Tue, 2 Jul 2024 08:50:02 +0800 Subject: [PATCH] chore: Update some type hints in config. (#5833) --- api/configs/app_config.py | 3 +++ api/configs/feature/__init__.py | 2 +- api/configs/middleware/__init__.py | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/api/configs/app_config.py b/api/configs/app_config.py index 4467b84c86..e5edc86bc3 100644 --- a/api/configs/app_config.py +++ b/api/configs/app_config.py @@ -8,6 +8,9 @@ from configs.middleware import MiddlewareConfig from configs.packaging import PackagingInfo +# TODO: Both `BaseModel` and `BaseSettings` has `model_config` attribute but they are in different types. +# This inheritance is depends on the order of the classes. +# It is better to use `BaseSettings` as the base class. class DifyConfig( # based on pydantic-settings BaseSettings, diff --git a/api/configs/feature/__init__.py b/api/configs/feature/__init__.py index d8ab749560..2205b0e169 100644 --- a/api/configs/feature/__init__.py +++ b/api/configs/feature/__init__.py @@ -136,7 +136,7 @@ class HttpConfig(BaseModel): def CONSOLE_CORS_ALLOW_ORIGINS(self) -> list[str]: return self.inner_CONSOLE_CORS_ALLOW_ORIGINS.split(',') - inner_WEB_API_CORS_ALLOW_ORIGINS: Optional[str] = Field( + inner_WEB_API_CORS_ALLOW_ORIGINS: str = Field( description='', validation_alias=AliasChoices('WEB_API_CORS_ALLOW_ORIGINS'), default='*', diff --git a/api/configs/middleware/__init__.py b/api/configs/middleware/__init__.py index b1957efb6b..6b3ed1a100 100644 --- a/api/configs/middleware/__init__.py +++ b/api/configs/middleware/__init__.py @@ -144,7 +144,7 @@ class CeleryConfig(DatabaseConfig): @computed_field @property - def CELERY_RESULT_BACKEND(self) -> str: + def CELERY_RESULT_BACKEND(self) -> str | None: return 'db+{}'.format(self.SQLALCHEMY_DATABASE_URI) \ if self.CELERY_BACKEND == 'database' else self.CELERY_BROKER_URL