From 7cbef584c007d8a0f83259e47734c6e0b04df4f3 Mon Sep 17 00:00:00 2001 From: Automated Action Date: Sat, 31 May 2025 21:22:25 +0000 Subject: [PATCH] Fix pydantic_settings import error Added fallback implementation for environments without pydantic_settings package and added pydantic-settings to requirements.txt to prevent future issues. --- app/core/config.py | 29 ++++++++++++++++++++++++++++- requirements.txt | 1 + 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/app/core/config.py b/app/core/config.py index 63ac1b3..35cae9a 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -1,6 +1,33 @@ +import os from pathlib import Path -from pydantic_settings import BaseSettings +from pydantic import BaseModel + +# Try to use pydantic_settings if available, otherwise fallback to a simple BaseModel +try: + from pydantic_settings import BaseSettings +except ImportError: + # Fallback for environments without pydantic_settings + # In Pydantic v2, BaseSettings was moved to pydantic_settings package + class BaseSettings(BaseModel): + """ + Simplified BaseSettings implementation for compatibility. + """ + class Config: + env_file = ".env" + case_sensitive = True + + def __init__(self, **kwargs): + # Load environment variables + env_values = {} + for field_name, _ in self.__annotations__.items(): + env_val = os.environ.get(field_name) + if env_val is not None: + env_values[field_name] = env_val + + # Override with any provided values + env_values.update(kwargs) + super().__init__(**env_values) class Settings(BaseSettings): diff --git a/requirements.txt b/requirements.txt index a6797d5..b75a53b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,6 +3,7 @@ uvicorn>=0.22.0 sqlalchemy>=2.0.0 alembic>=1.11.0 pydantic>=2.0.0 +pydantic-settings>=2.0.0 python-dotenv>=1.0.0 ruff>=0.0.292 pathlib>=1.0.1 \ No newline at end of file