Add: option to disable SQLA connection pool.

This commit is contained in:
Arik Fraimovich 2017-10-15 15:09:18 +03:00
parent c5458af1a0
commit f7ffc75ba4

View File

@ -33,7 +33,17 @@ from sqlalchemy.orm.exc import NoResultFound # noqa: F401
from sqlalchemy.types import TypeDecorator
from functools import reduce
db = SQLAlchemy(session_options={
class SQLAlchemyExt(SQLAlchemy):
def apply_pool_defaults(self, app, options):
if settings.SQLALCHEMY_DISABLE_POOL:
from sqlalchemy.pool import NullPool
options['poolclass'] = NullPool
else:
return super(SQLAlchemyExt, self).apply_pool_defaults(app, options)
db = SQLAlchemyExt(session_options={
'expire_on_commit': False
})