From 1d734ce95c7a845cd509685a846b9d476c597fe7 Mon Sep 17 00:00:00 2001 From: Stefan van der Weide Date: Mon, 2 Aug 2021 17:27:41 +0200 Subject: [PATCH] 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 --- .github/workflows/unit_tests.yml | 2 ++ flask_jwt_extended/view_decorators.py | 10 +++++----- tox.ini | 3 ++- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml index b8f4734d..338941ec 100644 --- a/.github/workflows/unit_tests.yml +++ b/.github/workflows/unit_tests.yml @@ -22,3 +22,5 @@ jobs: run: pip install tox - name: Run Tox run: tox -e py + - name: Run Tox Flask 1 + run: tox -e flask1 diff --git a/flask_jwt_extended/view_decorators.py b/flask_jwt_extended/view_decorators.py index f3ba655e..9defc595 100644 --- a/flask_jwt_extended/view_decorators.py +++ b/flask_jwt_extended/view_decorators.py @@ -121,12 +121,12 @@ def decorator(*args, **kwargs): verify_jwt_in_request(optional, fresh, refresh, locations) # Compatibility with flask < 2.0 - try: + if hasattr(current_app, "ensure_sync") and callable( + getattr(current_app, "ensure_sync", None) + ): return current_app.ensure_sync(fn)(*args, **kwargs) - except AttributeError as e: # pragma: no cover - if str(e) != "'Flask' object has no attribute 'ensure_sync'": - raise - return fn(*args, **kwargs) + + return fn(*args, **kwargs) # pragma: no cover return decorator diff --git a/tox.ini b/tox.ini index a9b46292..a0d5f940 100644 --- a/tox.ini +++ b/tox.ini @@ -4,7 +4,7 @@ # and then run "tox" from this directory. [tox] -envlist = py36,py37,py38,py39,pypy3,coverage,style,docs +envlist = py36,py37,py38,py39,pypy3,flask1,coverage,style,docs [testenv] commands = @@ -13,6 +13,7 @@ deps = pytest cryptography python-dateutil + flask1: flask == 1.1.4 [testenv:coverage] commands =