Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/database/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
logger = logging.getLogger(__name__)

connection_string = settings.database.assemble_db_connection(async_=True)
logger.debug(f"Database connection string: {connection_string}")
async_engine = create_async_engine(connection_string, poolclass=NullPool)
# repr() of a SQLAlchemy URL masks the password.
logger.debug(f"Database URL: {async_engine.url!r}")
AsyncSessionLocal: async_sessionmaker[AsyncSession] = async_sessionmaker(
async_engine, autoflush=True, expire_on_commit=False, class_=AsyncSession
)
16 changes: 16 additions & 0 deletions tests/src/database/test_session.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import importlib
import logging

from src.core import settings
from src.database import session


def test_creating_the_engine_does_not_log_the_password(caplog, monkeypatch):
# The alembic migration tests call logging.config.fileConfig, which disables existing loggers.
monkeypatch.setattr(logging.getLogger("src.database.session"), "disabled", False)
monkeypatch.setattr(settings.database, "PASSWORD", "not-in-the-logs")

with caplog.at_level(logging.DEBUG):
importlib.reload(session)

assert "not-in-the-logs" not in caplog.text
Loading