Skip to content

Commit 1d734ce

Browse files
Fix/support flask 2 and flask 1 (#440)
* Updated check for ensure_sync * Added flask 1.1.4 to seperate tox env * Updated Github Actions unit test workflow * Hacky way of making the unit tests work for Flask 1
1 parent afbe892 commit 1d734ce

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

.github/workflows/unit_tests.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@ jobs:
2222
run: pip install tox
2323
- name: Run Tox
2424
run: tox -e py
25+
- name: Run Tox Flask 1
26+
run: tox -e flask1

flask_jwt_extended/view_decorators.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,12 @@ def decorator(*args, **kwargs):
121121
verify_jwt_in_request(optional, fresh, refresh, locations)
122122

123123
# Compatibility with flask < 2.0
124-
try:
124+
if hasattr(current_app, "ensure_sync") and callable(
125+
getattr(current_app, "ensure_sync", None)
126+
):
125127
return current_app.ensure_sync(fn)(*args, **kwargs)
126-
except AttributeError as e: # pragma: no cover
127-
if str(e) != "'Flask' object has no attribute 'ensure_sync'":
128-
raise
129-
return fn(*args, **kwargs)
128+
129+
return fn(*args, **kwargs) # pragma: no cover
130130

131131
return decorator
132132

tox.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# and then run "tox" from this directory.
55

66
[tox]
7-
envlist = py36,py37,py38,py39,pypy3,coverage,style,docs
7+
envlist = py36,py37,py38,py39,pypy3,flask1,coverage,style,docs
88

99
[testenv]
1010
commands =
@@ -13,6 +13,7 @@ deps =
1313
pytest
1414
cryptography
1515
python-dateutil
16+
flask1: flask == 1.1.4
1617

1718
[testenv:coverage]
1819
commands =

0 commit comments

Comments
 (0)