Skip to content

Commit 6baf1bf

Browse files
fix: default values for non QueuePool pool classes
1 parent 06f79a1 commit 6baf1bf

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
@@ -36,18 +36,21 @@ def utc_tzinfo_factory(offset):
3636
utc_tzinfo_factory = None
3737
from sqlalchemy import event
3838
from sqlalchemy.dialects import postgresql
39-
from sqlalchemy.pool import manage
39+
from sqlalchemy.pool import manage, QueuePool
40+
41+
POOL_CLS = getattr(settings, 'DATABASE_POOL_CLASS', 'sqlalchemy.pool.QueuePool')
42+
pool_module_name, pool_cls_name = POOL_CLS.rsplit('.', 1)
43+
pool_cls = getattr(import_module(pool_module_name), pool_cls_name)
4044

4145
# DATABASE_POOL_ARGS should be something like:
42-
# {'max_overflow':10, 'pool_size':5, 'recycle':300}
43-
pool_args = {'max_overflow': 10, 'pool_size': 5, 'recycle': 300}
46+
# if pool class is QueuePool then
47+
# {'max_overflow':10, 'pool_size':5, 'recycle':300}
48+
# otherwise
49+
# {}
50+
pool_args = {'max_overflow': 10, 'pool_size': 5, 'recycle': 300} if isinstance(pool_cls, QueuePool) else {}
4451
pool_args.update(getattr(settings, 'DATABASE_POOL_ARGS', {}))
4552
dialect = postgresql.dialect(dbapi=psycopg2)
4653
pool_args['dialect'] = dialect
47-
48-
POOL_CLS = getattr(settings, 'DATABASE_POOL_CLASS', 'sqlalchemy.pool.QueuePool')
49-
pool_module_name, pool_cls_name = POOL_CLS.rsplit('.', 1)
50-
pool_cls = getattr(import_module(pool_module_name), pool_cls_name)
5154
pool_args['poolclass'] = pool_cls
5255

5356
db_pool = manage(Database, **pool_args)

0 commit comments

Comments
 (0)