diff --git a/app/__init__.py b/app/__init__.py index 192eab708..6e571a0c0 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -77,18 +77,7 @@ class SQLAlchemy(_SQLAlchemy): return (sa_url, options) -# Set db engine settings here for now. -# They were not being set previous (despite environmental variables with appropriate -# sounding names) and were defaulting to low values -db = SQLAlchemy( - engine_options={ - "pool_size": config.Config.SQLALCHEMY_POOL_SIZE, - "max_overflow": 10, - "pool_timeout": config.Config.SQLALCHEMY_POOL_TIMEOUT, - "pool_recycle": config.Config.SQLALCHEMY_POOL_RECYCLE, - "pool_pre_ping": True, - } -) +db = None migrate = None notify_celery = NotifyCelery() aws_ses_client = None @@ -189,10 +178,24 @@ def create_app(application): init_app(application) request_helper.init_app(application) - db.init_app(application) logging.init_app(application) # start lazy initialization for gevent + + # Set db engine settings here for now. + # They were not being set previous (despite environmental variables with appropriate + # sounding names) and were defaulting to low values + db = SQLAlchemy( + engine_options={ + "pool_size": config.Config.SQLALCHEMY_POOL_SIZE, + "max_overflow": 10, + "pool_timeout": config.Config.SQLALCHEMY_POOL_TIMEOUT, + "pool_recycle": config.Config.SQLALCHEMY_POOL_RECYCLE, + "pool_pre_ping": True, + } + ) + db.init_app(application) + migrate = Migrate() migrate.init_app(application, db=db) if zendesk_client is None: diff --git a/tests/app/dao/test_annual_billing_dao.py b/tests/app/dao/test_annual_billing_dao.py index 72a7d3a3a..f585ab614 100644 --- a/tests/app/dao/test_annual_billing_dao.py +++ b/tests/app/dao/test_annual_billing_dao.py @@ -2,7 +2,8 @@ import pytest from freezegun import freeze_time from sqlalchemy import select -from app import db +import application +from app import create_app, db from app.dao.annual_billing_dao import ( dao_create_or_update_annual_billing_for_year, dao_get_all_free_sms_fragment_limit, @@ -18,6 +19,7 @@ from tests.app.db import create_annual_billing, create_service def test_dao_update_free_sms_fragment_limit(notify_db_session, sample_service): + create_app(application) new_limit = 9999 year = get_current_calendar_year_start_year() dao_create_or_update_annual_billing_for_year(sample_service.id, new_limit, year)