Skip to content

Commit d135330

Browse files
fix: default values for non QueuePool pool classes
1 parent adc5851 commit d135330

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

django_postgrespool2/base.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,21 @@ def async_unsafe(func):
2222
utc_tzinfo_factory = None
2323
from sqlalchemy import event
2424
from sqlalchemy.dialects import postgresql
25-
from sqlalchemy.pool import manage
25+
from sqlalchemy.pool import manage, QueuePool
26+
27+
POOL_CLS = getattr(settings, 'DATABASE_POOL_CLASS', 'sqlalchemy.pool.QueuePool')
28+
pool_module_name, pool_cls_name = POOL_CLS.rsplit('.', 1)
29+
pool_cls = getattr(import_module(pool_module_name), pool_cls_name)
2630

2731
# DATABASE_POOL_ARGS should be something like:
28-
# {'max_overflow':10, 'pool_size':5, 'recycle':300}
29-
pool_args = {'max_overflow': 10, 'pool_size': 5, 'recycle': 300}
32+
# if pool class is QueuePool then
33+
# {'max_overflow':10, 'pool_size':5, 'recycle':300}
34+
# otherwise
35+
# {}
36+
pool_args = {'max_overflow': 10, 'pool_size': 5, 'recycle': 300} if isinstance(pool_cls, QueuePool) else {}
3037
pool_args.update(getattr(settings, 'DATABASE_POOL_ARGS', {}))
3138
dialect = postgresql.dialect(dbapi=psycopg2)
3239
pool_args['dialect'] = dialect
33-
34-
POOL_CLS = getattr(settings, 'DATABASE_POOL_CLASS', 'sqlalchemy.pool.QueuePool')
35-
pool_module_name, pool_cls_name = POOL_CLS.rsplit('.', 1)
36-
pool_cls = getattr(import_module(pool_module_name), pool_cls_name)
3740
pool_args['poolclass'] = pool_cls
3841

3942
db_pool = manage(Database, **pool_args)

0 commit comments

Comments
 (0)