Skip to content

Commit

Permalink
catch AttributeError instead of TypeError
Browse files Browse the repository at this point in the history
  • Loading branch information
davidism committed Sep 11, 2023
1 parent 821e37f commit 8980a34
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/flask_migrate/templates/aioflask-multidb/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion src/flask_migrate/templates/aioflask/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions src/flask_migrate/templates/flask-multidb/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@

def get_engine(bind_key=None):
try:
# this works with Flask-SQLAlchemy<3 and Alchemical
# this works with Flask-SQLAlchemy<3.0 and Alchemical
return current_app.extensions['migrate'].db.get_engine(bind=bind_key)
except TypeError:
# this works with Flask-SQLAlchemy>=3
except (TypeError, AttributeError):
# this works with Flask-SQLAlchemy>=3.0
return current_app.extensions['migrate'].db.engines.get(bind_key)


Expand Down
2 changes: 1 addition & 1 deletion src/flask_migrate/templates/flask/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 8980a34

Please sign in to comment.