Skip to content

Commit 9a1cdfe

Browse files
committed
keep deprecated get_engine for another version
1 parent 9e19238 commit 9a1cdfe

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/flask_sqlalchemy/extension.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,34 @@ def engine(self) -> sa.engine.Engine:
708708
"""
709709
return self.engines[None]
710710

711+
def get_engine(
712+
self, bind_key: str | None = None, **kwargs: t.Any
713+
) -> sa.engine.Engine:
714+
"""Get the engine for the given bind key for the current application.
715+
This requires that a Flask application context is active.
716+
717+
:param bind_key: The name of the engine.
718+
719+
.. deprecated:: 3.0
720+
Will be removed in Flask-SQLAlchemy 3.2. Use ``engines[key]`` instead.
721+
722+
.. versionchanged:: 3.0
723+
Renamed the ``bind`` parameter to ``bind_key``. Removed the ``app``
724+
parameter.
725+
"""
726+
warnings.warn(
727+
"'get_engine' is deprecated and will be removed in Flask-SQLAlchemy"
728+
" 3.2. Use 'engine' or 'engines[key]' instead. If you're using"
729+
" Flask-Migrate or Alembic, you'll need to update your 'env.py' file.",
730+
DeprecationWarning,
731+
stacklevel=2,
732+
)
733+
734+
if "bind" in kwargs:
735+
bind_key = kwargs.pop("bind")
736+
737+
return self.engines[bind_key]
738+
711739
def get_or_404(
712740
self,
713741
entity: type[_O],

0 commit comments

Comments
 (0)