From aaac87335a9253a1546355b7c456c80a9f640846 Mon Sep 17 00:00:00 2001 From: Automated Action Date: Mon, 9 Jun 2025 13:43:01 +0000 Subject: [PATCH] Fix ModuleNotFoundError for pydantic_settings - Added pydantic and pydantic-settings to requirements.txt - Updated config.py to use proper Pydantic v2 imports and patterns - Updated schemas to use Pydantic v2 configuration format - Replaced orm_mode with from_attributes=True in schema models - Applied code formatting with Ruff --- app/core/config.py | 6 ++---- app/db/migrations/env.py | 1 + app/schemas/file.py | 8 +++----- requirements.txt | 2 ++ 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/app/core/config.py b/app/core/config.py index 5231be8..4129b91 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -1,6 +1,6 @@ from pathlib import Path -from pydantic_settings import BaseSettings +from pydantic_settings import BaseSettings, SettingsConfigDict class Settings(BaseSettings): @@ -20,9 +20,7 @@ class Settings(BaseSettings): # Configure max file size (10MB by default) MAX_FILE_SIZE: int = 10 * 1024 * 1024 # 10MB in bytes - class Config: - case_sensitive = True - env_file = ".env" + model_config = SettingsConfigDict(case_sensitive=True, env_file=".env") # Create settings instance diff --git a/app/db/migrations/env.py b/app/db/migrations/env.py index da958d4..c417af5 100644 --- a/app/db/migrations/env.py +++ b/app/db/migrations/env.py @@ -14,6 +14,7 @@ sys.path.insert(0, str(current_path)) # Import Base after setting up sys.path from app.db.base import Base # noqa: E402 + # Import all models to register them with SQLAlchemy metadata from app.models.file import File # noqa: E402, F401 - import needed for Alembic to detect models diff --git a/app/schemas/file.py b/app/schemas/file.py index 2b72759..fa6783d 100644 --- a/app/schemas/file.py +++ b/app/schemas/file.py @@ -1,5 +1,5 @@ from datetime import datetime -from pydantic import BaseModel +from pydantic import BaseModel, ConfigDict class FileBase(BaseModel): @@ -25,8 +25,7 @@ class FileInDB(FileBase): created_at: datetime updated_at: datetime - class Config: - orm_mode = True + model_config = ConfigDict(from_attributes=True) class FileResponse(FileBase): @@ -37,5 +36,4 @@ class FileResponse(FileBase): created_at: datetime download_url: str - class Config: - orm_mode = True + model_config = ConfigDict(from_attributes=True) diff --git a/requirements.txt b/requirements.txt index ae4db1d..95c3185 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,4 +4,6 @@ sqlalchemy>=2.0.0 alembic>=1.10.0 python-multipart>=0.0.6 python-dotenv>=1.0.0 +pydantic>=2.0.0 +pydantic-settings>=2.0.0 ruff>=0.1.0 \ No newline at end of file