Skip to content

Commit bd13c54

Browse files
committed
don't require passing app to get_engine
1 parent d651a70 commit bd13c54

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

flask_sqlalchemy/__init__.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -892,28 +892,29 @@ def engine(self):
892892
is used this might raise a :exc:`RuntimeError` if no application is
893893
active at the moment.
894894
"""
895-
return self.get_engine(self.get_app())
895+
return self.get_engine()
896896

897-
def make_connector(self, app, bind=None):
897+
def make_connector(self, app=None, bind=None):
898898
"""Creates the connector for a given state and bind."""
899-
return _EngineConnector(self, app, bind)
899+
return _EngineConnector(self, self.get_app(app), bind)
900900

901-
def get_engine(self, app, bind=None):
902-
"""Returns a specific engine.
901+
def get_engine(self, app=None, bind=None):
902+
"""Returns a specific engine."""
903+
904+
app = self.get_app(app)
905+
state = get_state(app)
903906

904-
.. versionadded:: 0.12
905-
"""
906907
with self._engine_lock:
907-
state = get_state(app)
908908
connector = state.connectors.get(bind)
909+
909910
if connector is None:
910911
connector = self.make_connector(app, bind)
911912
state.connectors[bind] = connector
913+
912914
return connector.get_engine()
913915

914916
def get_app(self, reference_app=None):
915-
"""Helper method that implements the logic to look up an application.
916-
"""
917+
"""Helper method that implements the logic to look up an application."""
917918
if reference_app is not None:
918919
return reference_app
919920
if self.app is not None:

0 commit comments

Comments
 (0)