Closed h2appy closed 1 year ago
import os from functools import lru_cache from pydantic import PostgresDsn, RedisDsn from pydantic_settings import BaseSettings class Settings(BaseSettings): asyncpg_url: PostgresDsn = os.getenv("SQL_URL") secret_key: str = os.getenv("FERNET_KEY") redis_url: RedisDsn = os.getenv("REDIS_URL") jwt_algorithm: str = os.getenv("JWT_ALGORITHM") jwt_expire: int = os.getenv("JWT_EXPIRE") @lru_cache def get_settings(): return Settings() settings = get_settings()
It's the same as below, I think. Because get_setting() with @lru_cache will always return the same object.:
import os from functools import lru_cache from pydantic import PostgresDsn, RedisDsn from pydantic_settings import BaseSettings class Settings(BaseSettings): asyncpg_url: PostgresDsn = os.getenv("SQL_URL") secret_key: str = os.getenv("FERNET_KEY") redis_url: RedisDsn = os.getenv("REDIS_URL") jwt_algorithm: str = os.getenv("JWT_ALGORITHM") jwt_expire: int = os.getenv("JWT_EXPIRE") settings = Setting()
@h2appy thx for rising this. Think it is left over from older fastapi versions. In case of settings = Setting() it will be same object in memory so PR most welcome.
settings = Setting()
It's the same as below, I think. Because get_setting() with @lru_cache will always return the same object.: