Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot decorate more than one view with @inflate #5

Open
whsu00 opened this issue May 25, 2023 · 0 comments · May be fixed by #6
Open

cannot decorate more than one view with @inflate #5

whsu00 opened this issue May 25, 2023 · 0 comments · May be fixed by #6

Comments

@whsu00
Copy link

whsu00 commented May 25, 2023

flask requires view names to be unique, and since the raw wrapper function is returned by inflate, using the @inflate decorator on multiple views raises an exception:

from flask import Flask
from flask_inflate import inflate

app = Flask(__name__)

@app.route('/a')
@inflate
def a():
    return 'a'

@app.route('/b')
@inflate
def b():
    return 'b'
AssertionError: View function mapping is overwriting an existing endpoint function: wrapper

one solution is to decorate the inner function with python's built-in @functools.wraps:

@@ -1,3 +1,4 @@
+import functools
 import gzip
 from flask import request

@@ -18,6 +19,7 @@ def inflate(func):
     """
     A decorator to inflate content of a single view function
     """
+    @functools.wraps(func)
     def wrapper(*args, **kwargs):
         _inflate_gzipped_content()
         return func(*args, **kwargs)

versions:

# Name                    Version                   Build  Channel
flask                     2.3.2                    pypi_0    pypi
flask-inflate             0.3                      pypi_0    pypi
@whsu00 whsu00 linked a pull request May 25, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant