@@ -36,18 +36,21 @@ def utc_tzinfo_factory(offset):
3636 utc_tzinfo_factory = None
3737from sqlalchemy import event
3838from 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 {}
4451pool_args .update (getattr (settings , 'DATABASE_POOL_ARGS' , {}))
4552dialect = postgresql .dialect (dbapi = psycopg2 )
4653pool_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 )
5154pool_args ['poolclass' ] = pool_cls
5255
5356db_pool = manage (Database , ** pool_args )
0 commit comments