fix (db): Use variable engine settings
This commit is contained in:
parent
3c9c094d0f
commit
bd38ddf1dd
|
|
@ -5,6 +5,7 @@ from typing import Annotated, Any, ClassVar, Optional
|
|||
import tomllib
|
||||
from dotenv import load_dotenv
|
||||
from pydantic import Field, field_validator
|
||||
from pydantic_core.core_schema import FieldValidationInfo
|
||||
from pydantic_settings import (
|
||||
BaseSettings,
|
||||
PydanticBaseSettingsSource,
|
||||
|
|
@ -97,7 +98,7 @@ class TomlSettings(BaseSettings):
|
|||
env_settings: PydanticBaseSettingsSource,
|
||||
dotenv_settings: PydanticBaseSettingsSource,
|
||||
file_secret_settings: PydanticBaseSettingsSource,
|
||||
):
|
||||
) -> tuple[PydanticBaseSettingsSource, ...]:
|
||||
# Return sources in priority order (first is lowest priority)
|
||||
return (
|
||||
init_settings,
|
||||
|
|
@ -133,9 +134,18 @@ class DBSettings(TomlSettings):
|
|||
class AuthSettings(TomlSettings):
|
||||
model_config = SettingsConfigDict(env_prefix="AUTH_")
|
||||
|
||||
USE_AUTH: bool = True
|
||||
USE_AUTH: bool = False
|
||||
JWT_SECRET: Optional[str] = None # Must be set if USE_AUTH is true
|
||||
|
||||
@field_validator("JWT_SECRET")
|
||||
@classmethod
|
||||
def _require_jwt_secret(
|
||||
cls, v: Optional[str], info: FieldValidationInfo
|
||||
) -> Optional[str]:
|
||||
if info.data.get("USE_AUTH") and v is None:
|
||||
raise ValueError("JWT_SECRET must be set if USE_AUTH is true")
|
||||
return v
|
||||
|
||||
|
||||
class SentrySettings(TomlSettings):
|
||||
model_config = SettingsConfigDict(env_prefix="SENTRY_")
|
||||
|
|
|
|||
|
|
@ -38,13 +38,7 @@ engine = create_async_engine(
|
|||
settings.DB.CONNECTION_URI,
|
||||
connect_args=connect_args,
|
||||
echo=settings.DB.SQL_DEBUG,
|
||||
pool_pre_ping=settings.DB.POOL_PRE_PING,
|
||||
pool_size=settings.DB.POOL_SIZE,
|
||||
max_overflow=settings.DB.MAX_OVERFLOW,
|
||||
pool_timeout=settings.DB.POOL_TIMEOUT,
|
||||
pool_recycle=settings.DB.POOL_RECYCLE,
|
||||
pool_use_lifo=settings.DB.POOL_USE_LIFO,
|
||||
poolclass=pool_class,
|
||||
**engine_kwargs,
|
||||
)
|
||||
|
||||
SessionLocal = async_sessionmaker(
|
||||
|
|
|
|||
|
|
@ -181,6 +181,7 @@ def auth_client(client, request, monkeypatch):
|
|||
"""
|
||||
# Ensure USE_AUTH is always True for this fixture
|
||||
monkeypatch.setattr(settings.AUTH, "USE_AUTH", True)
|
||||
monkeypatch.setattr(settings.AUTH, "JWT_SECRET", "test-secret")
|
||||
|
||||
# Clear any existing Authorization header
|
||||
client.headers.pop("Authorization", None)
|
||||
|
|
|
|||
Loading…
Reference in New Issue