Fix Pydantic error in config.py

- Add ClassVar type annotation to DB_DIR to fix the Pydantic validation error
- Update Config to model_config for Pydantic v2 compatibility
- Ensure the Settings class properly handles the database directory path
This commit is contained in:
Automated Action 2025-06-10 09:21:05 +00:00
parent 439330125e
commit 5c826d8908

View File

@ -1,5 +1,5 @@
from pathlib import Path from pathlib import Path
from typing import List from typing import ClassVar, List
from pydantic import AnyHttpUrl, EmailStr, validator from pydantic import AnyHttpUrl, EmailStr, validator
from pydantic_settings import BaseSettings from pydantic_settings import BaseSettings
@ -16,7 +16,7 @@ class Settings(BaseSettings):
ACCESS_TOKEN_EXPIRE_MINUTES: int = 60 * 24 * 7 # 7 days ACCESS_TOKEN_EXPIRE_MINUTES: int = 60 * 24 * 7 # 7 days
# Database setup # Database setup
DB_DIR = Path("/app") / "storage" / "db" DB_DIR: ClassVar[Path] = Path("/app") / "storage" / "db"
DB_DIR.mkdir(parents=True, exist_ok=True) DB_DIR.mkdir(parents=True, exist_ok=True)
SQLALCHEMY_DATABASE_URL: str = f"sqlite:///{DB_DIR}/db.sqlite" SQLALCHEMY_DATABASE_URL: str = f"sqlite:///{DB_DIR}/db.sqlite"
@ -58,9 +58,10 @@ class Settings(BaseSettings):
and values.get("EMAILS_FROM_EMAIL") and values.get("EMAILS_FROM_EMAIL")
) )
class Config: model_config = {
case_sensitive = True "case_sensitive": True,
env_file = ".env" "env_file": ".env"
}
settings = Settings() settings = Settings()