Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for arbitrary Pool configuration #525

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ A list of configuration keys currently understood by the extension:
that it will be disabled by default in
the future. This requires extra memory
and should be disabled if not needed.
``SQLALCHEMY_POOL`` A reference to a SQLAlchemy Pool object,
when used, other pool-related
configuration elements will be
disregarded in favor of this pool object.
This allows for the full flexibility
that SQLAlchemy provides around pools.
================================== =========================================

.. versionadded:: 0.8
Expand Down
7 changes: 6 additions & 1 deletion flask_sqlalchemy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,11 @@ def get_engine(self):
return self._engine
info = make_url(uri)
options = {'convert_unicode': True}
self._sa.apply_pool_defaults(self._app, options)
pool = self._app.config['SQLALCHEMY_POOL']
if pool:
options['pool'] = pool
else:
self._sa.apply_pool_defaults(self._app, options)
self._sa.apply_driver_hacks(self._app, info, options)
if echo:
options['echo'] = echo
Expand Down Expand Up @@ -830,6 +834,7 @@ def init_app(self, app):
app.config.setdefault('SQLALCHEMY_POOL_RECYCLE', None)
app.config.setdefault('SQLALCHEMY_MAX_OVERFLOW', None)
app.config.setdefault('SQLALCHEMY_COMMIT_ON_TEARDOWN', False)
app.config.setdefault('SQLALCHEMY_POOL', None)
track_modifications = app.config.setdefault(
'SQLALCHEMY_TRACK_MODIFICATIONS', None
)
Expand Down