Хочу разбить конфиг пайдантик на классы, для читаемости и чистоты, но выдает ошибка аля missing prefix или мб value.
Вот сама ошибка:
pydantic_core._pydantic_core.ValidationError: 1 validation error for APISettings
prefix
Field required [type=missing, input_value={}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.9/v/missing
Вот конфиг:
from pydantic import BaseModel, FilePath, StrictStr, PositiveInt
from pydantic_settings import BaseSettings
class APISettings(BaseModel):
prefix: StrictStr
class Config:
env_prefix = "API_"
class PostgresSettings(BaseModel):
url: StrictStr
class Config:
env_prefix = "POSTGRES_"
class AuthJWTSettings(BaseModel):
private_key_path: FilePath
public_key_path: FilePath
algorithm: StrictStr
access_token_expire_minutes: PositiveInt
class Config:
env_prefix = "AUTH_"
class RedisSettings(BaseModel):
url: StrictStr
ttl: PositiveInt
class Config:
env_prefix = "REDIS_"
class Settings(BaseSettings):
api: APISettings = APISettings()
postgres: PostgresSettings = PostgresSettings()
auth: AuthJWTSettings = AuthJWTSettings()
redis: RedisSettings = RedisSettings()
class Config:
env_file = ".env"
env_file_encoding = "utf-8"
extra = "ignore"
settings = Settings()
Вот ENV:
# FROM .ENV IMPORT TO PYDANTIC SETTINGS
# api
API_prefix=...
# postgres data in app
POSTGRES_url=...
# redis
REDIS_url=...
REDIS_ttl=...
# auth
AUTH_private_key_path=...
AUTH_public_key_path=...
AUTH_algorithm=...
AUTH_access_token_expire_minutes=...
AUTH_refresh_token_expire_days=...
Что может быть не так?
При указании всех значений в основном Settings классе ошибок нет.