Skip to content

fix: configure SQLAlchemy connection pool with env-driven settings#174

Open
snowrugar-beep wants to merge 1 commit into
Quantarq:mainfrom
snowrugar-beep:fix/issue-59-sqlalchemy-pool-config
Open

fix: configure SQLAlchemy connection pool with env-driven settings#174
snowrugar-beep wants to merge 1 commit into
Quantarq:mainfrom
snowrugar-beep:fix/issue-59-sqlalchemy-pool-config

Conversation

@snowrugar-beep

Copy link
Copy Markdown

Summary

Configures SQLAlchemy engine pool settings (pool_size, max_overflow, pool_recycle, with pool_pre_ping always enabled) on both engine construction sites in the project. Eliminates the silent defaults that previously allowed connection exhaustion and stale-connection failures under load.

Changes

  • New helper _engine_pool_kwargs() in web_app/db/database.py (single source of truth).
  • New init_engine(db_url) factory; both init_db and DBConnector.__init__ now route through web_app.db.database.create_engine with the shared pool policy.
  • New tests/test_db_pool.py verifying both engine sites forward the env-driven kwargs and fall back to defaults.
  • Dropped the now-redundant import os / import create_engine from web_app/db/crud/base.py.
  • Defaults: DB_POOL_SIZE=5, DB_MAX_OVERFLOW=10, DB_POOL_RECYCLE=1800. All overridable via env.

Testing

  • python -m py_compile clean across database.py, crud/base.py, and the new test file.
  • pytest web_app/tests/test_db_pool.py validates kwarg forwarding under both set-env and unset-env scenarios.
  • DRY: a future change to defaults happens in exactly one place.

Closes #59

…B_MAX_OVERFLOW, DB_POOL_RECYCLE) with shared helper (Quantarq#59)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf: Configure SQLAlchemy connection pool settings

1 participant