Allow engine options to be set through the constructor like session options.#487
Closed
keithjstone wants to merge 1 commit into
Closed
Allow engine options to be set through the constructor like session options.#487keithjstone wants to merge 1 commit into
keithjstone wants to merge 1 commit into
Conversation
ThiefMaster
reviewed
Mar 20, 2017
| app.config['SQLALCHEMY_BINDS'] = { | ||
| 'foo': 'sqlite://' | ||
| } | ||
| db = fsa.SQLAlchemy(app, engine_options=dict(echo=True)) |
Contributor
There was a problem hiding this comment.
Probably not the best example for a unit test considering this one can be set through the flask config (SQLALCHEMY_ECHO)
Contributor
|
For what it's worth, I think the approach I documented in this comment is a better approach that this PR as it permits the engine options to be set in the Flask configuration. The suggestion: options = {'convert_unicode': True}
self._sa.apply_pool_defaults(self._app, options)
self._sa.apply_driver_hacks(self._app, info, options)
if echo:
options['echo'] = echo
# next two lines are new
config_engine_opts = self._app.config.get('SQLALCHEMY_ENGINE_OPTS', {})
options.update(config_engine_opts)
self._engine = rv = sqlalchemy.create_engine(info, **options)And it's only two lines difference. |
|
👍 to having this in Flask configuration. |
This was referenced Feb 23, 2018
Contributor
|
Thank you for your contribution and sorry this took so long. I believe #684 will solve this use case. |
Author
|
Huge thanks for the fix! We had found a workaround locally so we could continue to use the published versions. Will be looking to update! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Package does not allow setting of custom engine options without monkey patching or inheriting the base class. This would allow options to be set and remembered prior to creating the engine in a blessed manner.
Our specific use-case is setting
use_native_uuidstoFalseon a postgres connection but I think this is more generally useful.