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

pass real app instead of current_app to connector #547

Merged
merged 1 commit into from
Sep 28, 2017
Merged
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 CHANGES
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Changelog
=========


Version 2.3.0
-------------

Expand All @@ -23,10 +24,15 @@ In development
removed in 3.0. (`#546`_)
- Models have a default ``repr`` that shows the model name and primary key.
(`#530`_)
- Fixed a bug where using ``init_app`` would cause connectors to always use the
``current_app`` rather than the app they were created for. This caused issues
when multiple apps were registered with the extension. (`#547`_)

.. _#530: https://github.com/mitsuhiko/flask-sqlalchemy/pull/530
.. _#541: https://github.com/mitsuhiko/flask-sqlalchemy/pull/541
.. _#546: https://github.com/mitsuhiko/flask-sqlalchemy/pull/546
.. _#547: https://github.com/mitsuhiko/flask-sqlalchemy/pull/547


Version 2.2
-----------
Expand Down
6 changes: 3 additions & 3 deletions flask_sqlalchemy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -887,14 +887,14 @@ def get_app(self, reference_app=None):
return reference_app

if current_app:
return current_app
return current_app._get_current_object()

if self.app is not None:
return self.app

raise RuntimeError(
'application not registered on db instance and no application'
'bound to current context'
'No application found. Either work inside a view function or push'
' an application context.'
)

def get_tables_for_bind(self, bind=None):
Expand Down
13 changes: 13 additions & 0 deletions tests/test_binds.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import flask_sqlalchemy as fsa


def test_basic_binds(app, db):
app.config['SQLALCHEMY_BINDS'] = {
Expand Down Expand Up @@ -78,3 +80,14 @@ class FooBoundModel(AbstractFooBoundModel):
metadata.reflect(bind=db.get_engine(app, 'foo'))
assert len(metadata.tables) == 1
assert 'foo_bound_model' in metadata.tables


def test_connector_cache(app):
db = fsa.SQLAlchemy()
db.init_app(app)

with app.app_context():
db.get_engine()

connector = fsa.get_state(app).connectors[None]
assert connector._app is app