File tree Expand file tree Collapse file tree 3 files changed +22
-3
lines changed Expand file tree Collapse file tree 3 files changed +22
-3
lines changed Original file line number Diff line number Diff line change 11Changelog
22=========
33
4+
45Version 2.3.0
56-------------
67
@@ -23,10 +24,15 @@ In development
2324 removed in 3.0. (`#546`_)
2425- Models have a default ``repr`` that shows the model name and primary key.
2526 (`#530`_)
27+ - Fixed a bug where using ``init_app`` would cause connectors to always use the
28+ ``current_app`` rather than the app they were created for. This caused issues
29+ when multiple apps were registered with the extension. (`#547`_)
2630
2731.. _#530: https://github.com/mitsuhiko/flask-sqlalchemy/pull/530
2832.. _#541: https://github.com/mitsuhiko/flask-sqlalchemy/pull/541
2933.. _#546: https://github.com/mitsuhiko/flask-sqlalchemy/pull/546
34+ .. _#547: https://github.com/mitsuhiko/flask-sqlalchemy/pull/547
35+
3036
3137Version 2.2
3238-----------
Original file line number Diff line number Diff line change @@ -887,14 +887,14 @@ def get_app(self, reference_app=None):
887887 return reference_app
888888
889889 if current_app :
890- return current_app
890+ return current_app . _get_current_object ()
891891
892892 if self .app is not None :
893893 return self .app
894894
895895 raise RuntimeError (
896- 'application not registered on db instance and no application '
897- 'bound to current context'
896+ 'No application found. Either work inside a view function or push '
897+ ' an application context. '
898898 )
899899
900900 def get_tables_for_bind (self , bind = None ):
Original file line number Diff line number Diff line change 1+ import flask_sqlalchemy as fsa
2+
13
24def test_basic_binds (app , db ):
35 app .config ['SQLALCHEMY_BINDS' ] = {
@@ -78,3 +80,14 @@ class FooBoundModel(AbstractFooBoundModel):
7880 metadata .reflect (bind = db .get_engine (app , 'foo' ))
7981 assert len (metadata .tables ) == 1
8082 assert 'foo_bound_model' in metadata .tables
83+
84+
85+ def test_connector_cache (app ):
86+ db = fsa .SQLAlchemy ()
87+ db .init_app (app )
88+
89+ with app .app_context ():
90+ db .get_engine ()
91+
92+ connector = fsa .get_state (app ).connectors [None ]
93+ assert connector ._app is app
You can’t perform that action at this time.
0 commit comments