Skip to content

Commit 4d1a61e

Browse files
committed
Disable the pool for sqlite by default if not in memory
1 parent 334b296 commit 4d1a61e

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

flaskext/sqlalchemy.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,21 @@ def apply_driver_hacks(self, app, info, options):
545545
info.query.setdefault('charset', 'utf8')
546546
options.setdefault('pool_size', 10)
547547
options.setdefault('pool_recycle', 7200)
548+
elif info.drivername == 'sqlite':
549+
pool_size = options.get('pool_size')
550+
# we go to memory and the pool size was explicitly set to 0
551+
# which is fail. Let the user know that
552+
if info.database in (None, '', ':memory:'):
553+
if pool_size == 0:
554+
raise RuntimeError('SQLite in memory database with an '
555+
'empty queue not possible do to data '
556+
'loss.')
557+
# if pool size is None or explicitly set to 0 we assume the
558+
# user did not want a queue for this sqlite connection and
559+
# hook in the null pool.
560+
elif not pool_size:
561+
from sqlalchemy.pool import NullPool
562+
options['poolclass'] = NullPool
548563

549564
unu = app.config['SQLALCHEMY_NATIVE_UNICODE']
550565
if unu is None:

0 commit comments

Comments
 (0)