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 1df2282
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions src/flask_migrate/templates/aioflask-multidb/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@

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


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

def get_engine():
try:
# this works with Flask-SQLAlchemy<3 and Alchemical
# this works with Flask-SQLAlchemy<3.1 and Alchemical
return current_app.extensions['migrate'].db.get_engine()
except TypeError:
# this works with Flask-SQLAlchemy>=3
except AttributeError:
# this works with Flask-SQLAlchemy>=3.1
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.1 and Alchemical
return current_app.extensions['migrate'].db.get_engine(bind=bind_key)
except TypeError:
# this works with Flask-SQLAlchemy>=3
except AttributeError:
# this works with Flask-SQLAlchemy>=3.1
return current_app.extensions['migrate'].db.engines.get(bind_key)


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

def get_engine():
try:
# this works with Flask-SQLAlchemy<3 and Alchemical
# this works with Flask-SQLAlchemy<3.1 and Alchemical
return current_app.extensions['migrate'].db.get_engine()
except TypeError:
# this works with Flask-SQLAlchemy>=3
except AttributeError:
# this works with Flask-SQLAlchemy>=3.1
return current_app.extensions['migrate'].db.engine


Expand Down

0 comments on commit 1df2282

Please sign in to comment.