From aa94a023601920edabf5c4d952701736d27c4577 Mon Sep 17 00:00:00 2001 From: Automated Action Date: Mon, 2 Jun 2025 14:37:17 +0000 Subject: [PATCH] Fix Pydantic model error by adding ClassVar annotation to DB_DIR and moving directory creation outside class definition --- app/core/config.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/app/core/config.py b/app/core/config.py index 61dc660..4f4cd1a 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -1,7 +1,8 @@ import os from pathlib import Path +from typing import ClassVar -from pydantic import BaseModel +from pydantic import BaseModel, Field class Settings(BaseModel): @@ -13,9 +14,10 @@ class Settings(BaseModel): ACCESS_TOKEN_EXPIRE_MINUTES: int = 60 * 24 * 7 # 7 days # Database - DB_DIR = Path("/app/storage/db") - DB_DIR.mkdir(parents=True, exist_ok=True) - SQLALCHEMY_DATABASE_URL: str = f"sqlite:///{DB_DIR}/db.sqlite" + DB_DIR: ClassVar[Path] = Path("/app/storage/db") + SQLALCHEMY_DATABASE_URL: str = Field( + default_factory=lambda: f"sqlite:///{Settings.DB_DIR}/db.sqlite" + ) # CORS CORS_ORIGINS: list[str] = ["*"] @@ -26,4 +28,7 @@ class Settings(BaseModel): } +# Create the database directory +Settings.DB_DIR.mkdir(parents=True, exist_ok=True) + settings = Settings()