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.
This commit is contained in:
parent
5f003a0aeb
commit
7cbef584c0
@ -1,6 +1,33 @@
|
|||||||
|
import os
|
||||||
from pathlib import Path
|
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):
|
class Settings(BaseSettings):
|
||||||
|
@ -3,6 +3,7 @@ uvicorn>=0.22.0
|
|||||||
sqlalchemy>=2.0.0
|
sqlalchemy>=2.0.0
|
||||||
alembic>=1.11.0
|
alembic>=1.11.0
|
||||||
pydantic>=2.0.0
|
pydantic>=2.0.0
|
||||||
|
pydantic-settings>=2.0.0
|
||||||
python-dotenv>=1.0.0
|
python-dotenv>=1.0.0
|
||||||
ruff>=0.0.292
|
ruff>=0.0.292
|
||||||
pathlib>=1.0.1
|
pathlib>=1.0.1
|
Loading…
x
Reference in New Issue
Block a user