@@ -22,18 +22,21 @@ def async_unsafe(func):
2222 utc_tzinfo_factory = None
2323from sqlalchemy import event
2424from 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 {}
3037pool_args .update (getattr (settings , 'DATABASE_POOL_ARGS' , {}))
3138dialect = postgresql .dialect (dbapi = psycopg2 )
3239pool_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 )
3740pool_args ['poolclass' ] = pool_cls
3841
3942db_pool = manage (Database , ** pool_args )
0 commit comments