Skip to content

Commit

Permalink
Remove use of deprecated flask.__version__
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelgrinberg committed Oct 30, 2023
1 parent 38d765b commit a21ecba
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/apifairy/decorators.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from functools import wraps

import flask
from flask import current_app, Response
from webargs.flaskparser import FlaskParser as BaseFlaskParser

Expand Down Expand Up @@ -28,12 +27,15 @@ def handle_error(self, error, req, schema, *, error_status_code,


def _ensure_sync(f):
if flask.__version__ < '2.' or hasattr(f, '_sync_ensured'):
if hasattr(f, '_sync_ensured'):
return f

@wraps(f)
def wrapper(*args, **kwargs):
return current_app.ensure_sync(f)(*args, **kwargs)
if hasattr(current_app, 'ensure_sync'):
return current_app.ensure_sync(f)(*args, **kwargs)
else: # pragma: no cover
return f(*args, **kwargs)

wrapper._sync_ensured = True
return wrapper
Expand Down

0 comments on commit a21ecba

Please sign in to comment.