Update to support Pydantic v2 syntax
- Replaced BaseSettings import from pydantic to pydantic-settings - Updated validator to field_validator with mode='before' - Changed Config inner class to model_config dict - Added pydantic-settings to requirements.txt
This commit is contained in:
parent
6330360ba1
commit
b9ff2c5c99
@ -1,7 +1,8 @@
|
||||
from pathlib import Path
|
||||
from typing import List
|
||||
from typing import List, Union
|
||||
|
||||
from pydantic import BaseSettings, validator
|
||||
from pydantic import field_validator
|
||||
from pydantic_settings import BaseSettings
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
@ -13,8 +14,8 @@ class Settings(BaseSettings):
|
||||
# CORS settings
|
||||
BACKEND_CORS_ORIGINS: List[str] = ["*"]
|
||||
|
||||
@validator("BACKEND_CORS_ORIGINS", pre=True)
|
||||
def assemble_cors_origins(cls, v: str | List[str]) -> List[str] | str:
|
||||
@field_validator("BACKEND_CORS_ORIGINS", mode="before")
|
||||
def assemble_cors_origins(cls, v: Union[str, List[str]]) -> Union[List[str], str]:
|
||||
if isinstance(v, str) and not v.startswith("["):
|
||||
return [i.strip() for i in v.split(",")]
|
||||
elif isinstance(v, (list, str)):
|
||||
@ -37,9 +38,10 @@ class Settings(BaseSettings):
|
||||
# Configure logging
|
||||
LOG_LEVEL: str = "INFO"
|
||||
|
||||
class Config:
|
||||
case_sensitive = True
|
||||
env_file = ".env"
|
||||
model_config = {
|
||||
"case_sensitive": True,
|
||||
"env_file": ".env"
|
||||
}
|
||||
|
||||
|
||||
# Create all necessary directories
|
||||
|
@ -4,6 +4,7 @@ sqlalchemy>=2.0.0
|
||||
alembic>=1.10.0
|
||||
pydantic>=2.0.0
|
||||
pydantic[email]>=2.0.0
|
||||
pydantic-settings>=2.0.0
|
||||
python-jose[cryptography]>=3.3.0
|
||||
passlib[bcrypt]>=1.7.4
|
||||
python-multipart>=0.0.6
|
||||
|
Loading…
x
Reference in New Issue
Block a user