11from typing import List , Literal
22
33from pydantic import AnyHttpUrl
4- from pydantic_settings import BaseSettings , SettingsConfigDict
4+ from pydantic_settings import (
5+ BaseSettings ,
6+ SettingsConfigDict ,
7+ PydanticBaseSettingsSource ,
8+ )
9+ from typing import Type
510from functools import lru_cache
611
712
@@ -15,13 +20,6 @@ class Settings(BaseSettings):
1520 database_type : str = "sqlmodel"
1621 current_env : Literal ["testing" , "default" ]
1722
18- @property
19- def get_table_schema (self ) -> str | None :
20- """Return table_schema if database_url does not start with sqlite, otherwise return None."""
21- if self .database_url .startswith ("sqlite" ):
22- return None
23- return self .database_schema
24-
2523 # CORS settings
2624 backend_cors_origins : List [str ] = ["http://localhost:8000" , "http://localhost:3000" ]
2725 cors_allow_credentials : bool = False
@@ -43,19 +41,33 @@ def get_table_schema(self) -> str | None:
4341 extra = "ignore" ,
4442 )
4543
46- """ @field_validator("database_schema")
47- def validate_schema(cls, v: str | None, values ) -> str | None:
48- # Only set database_schema if database_url doesn't start with sqlite
49- if values.data.get(" database_url", "") .startswith("sqlite"):
44+ @ property
45+ def get_table_schema ( self ) -> str | None :
46+ """Return table_schema if database_url does not start with sqlite, otherwise return None."""
47+ if self . database_url .startswith ("sqlite" ):
5048 return None
51- return v """
49+ return self . database_schema
5250
5351 @property
5452 def backend_cors_origins_list (self ) -> List [AnyHttpUrl ]:
5553 return [AnyHttpUrl (origin ) for origin in self .backend_cors_origins ]
5654
55+ @classmethod
56+ def settings_customise_sources (
57+ cls ,
58+ settings_cls : Type [BaseSettings ],
59+ init_settings : PydanticBaseSettingsSource ,
60+ env_settings : PydanticBaseSettingsSource ,
61+ dotenv_settings : PydanticBaseSettingsSource ,
62+ file_secret_settings : PydanticBaseSettingsSource ,
63+ ) -> tuple [PydanticBaseSettingsSource , ...]:
64+ return (
65+ env_settings ,
66+ dotenv_settings ,
67+ file_secret_settings ,
68+ )
69+
5770
58- # Singleton pattern to ensure only one settings instance
5971@lru_cache ()
6072def get_settings () -> "Settings" :
6173 return Settings ()
0 commit comments