Fix wrapped view function comparison
Wrapped functions are not comparable, see https://bugs.python.org/issue3564, therefore a marker is used to note when the function has been sync wrapped to allow comparison with the wrapped function instead. This ensures that multiple route decorators work without raising exceptions i.e., @app.route("/") @app.route("/a") async def index(): ... works.
This commit is contained in:
parent
fab26dcbe9
commit
5c6a0f0c12
3 changed files with 5 additions and 1 deletions
|
|
@ -1048,6 +1048,8 @@ class Flask(Scaffold):
|
|||
self.url_map.add(rule)
|
||||
if view_func is not None:
|
||||
old_func = self.view_functions.get(endpoint)
|
||||
if getattr(old_func, "_flask_sync_wrapper", False):
|
||||
old_func = old_func.__wrapped__
|
||||
if old_func is not None and old_func != view_func:
|
||||
raise AssertionError(
|
||||
"View function mapping is overwriting an existing"
|
||||
|
|
|
|||
|
|
@ -780,4 +780,5 @@ def run_async(func):
|
|||
|
||||
return async_to_sync(inner)(*args, **kwargs)
|
||||
|
||||
outer._flask_sync_wrapper = True
|
||||
return outer
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue