From f562178bbe1912912f3cb6877cbae8b0899c74da Mon Sep 17 00:00:00 2001 From: David Lord Date: Tue, 12 Sep 2023 03:39:26 -0700 Subject: [PATCH] Compatiblity fixes for Flask-SQLAlchemy >= 3.1 (#526) --- src/flask_migrate/templates/aioflask-multidb/env.py | 2 +- src/flask_migrate/templates/aioflask/env.py | 2 +- src/flask_migrate/templates/flask-multidb/env.py | 2 +- src/flask_migrate/templates/flask/env.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/flask_migrate/templates/aioflask-multidb/env.py b/src/flask_migrate/templates/aioflask-multidb/env.py index fa6fd3a..f14bd6c 100644 --- a/src/flask_migrate/templates/aioflask-multidb/env.py +++ b/src/flask_migrate/templates/aioflask-multidb/env.py @@ -23,7 +23,7 @@ def get_engine(bind_key=None): try: # this works with Flask-SQLAlchemy<3 and Alchemical return current_app.extensions['migrate'].db.get_engine(bind=bind_key) - except TypeError: + except (TypeError, AttributeError): # this works with Flask-SQLAlchemy>=3 return current_app.extensions['migrate'].db.engines.get(bind_key) diff --git a/src/flask_migrate/templates/aioflask/env.py b/src/flask_migrate/templates/aioflask/env.py index ecbd77f..3a1ece5 100644 --- a/src/flask_migrate/templates/aioflask/env.py +++ b/src/flask_migrate/templates/aioflask/env.py @@ -20,7 +20,7 @@ def get_engine(): try: # this works with Flask-SQLAlchemy<3 and Alchemical return current_app.extensions['migrate'].db.get_engine() - except TypeError: + except (TypeError, AttributeError): # this works with Flask-SQLAlchemy>=3 return current_app.extensions['migrate'].db.engine diff --git a/src/flask_migrate/templates/flask-multidb/env.py b/src/flask_migrate/templates/flask-multidb/env.py index ed6966f..31b8e72 100644 --- a/src/flask_migrate/templates/flask-multidb/env.py +++ b/src/flask_migrate/templates/flask-multidb/env.py @@ -22,7 +22,7 @@ def get_engine(bind_key=None): try: # this works with Flask-SQLAlchemy<3 and Alchemical return current_app.extensions['migrate'].db.get_engine(bind=bind_key) - except TypeError: + except (TypeError, AttributeError): # this works with Flask-SQLAlchemy>=3 return current_app.extensions['migrate'].db.engines.get(bind_key) diff --git a/src/flask_migrate/templates/flask/env.py b/src/flask_migrate/templates/flask/env.py index f497a74..4c97092 100644 --- a/src/flask_migrate/templates/flask/env.py +++ b/src/flask_migrate/templates/flask/env.py @@ -19,7 +19,7 @@ def get_engine(): try: # this works with Flask-SQLAlchemy<3 and Alchemical return current_app.extensions['migrate'].db.get_engine() - except TypeError: + except (TypeError, AttributeError): # this works with Flask-SQLAlchemy>=3 return current_app.extensions['migrate'].db.engine