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

Error with flask method view #38

Open
JacksonToomey opened this issue Jul 7, 2019 · 2 comments
Open

Error with flask method view #38

JacksonToomey opened this issue Jul 7, 2019 · 2 comments

Comments

@JacksonToomey
Copy link

When using flask's own MethodView with flask injector, the app fails with the error:

Traceback (most recent call last):
  File "/Users/jacksontoomey1/.virtualenvs/rooster-d4LzYqiE/lib/python3.7/site-packages/flask_injector.py", line 101, in wrap_class_based_view
    class_kwargs = fun_closure['class_kwargs']
KeyError: 'class_kwargs'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "example.py", line 28, in <module>
    FlaskInjector(app=app, modules=[])
  File "/Users/jacksontoomey1/.virtualenvs/rooster-d4LzYqiE/lib/python3.7/site-packages/flask_injector.py", line 317, in __init__
    process_dict(container, injector)
  File "/Users/jacksontoomey1/.virtualenvs/rooster-d4LzYqiE/lib/python3.7/site-packages/flask_injector.py", line 344, in process_dict
    d[key] = wrap_fun(value, injector)
  File "/Users/jacksontoomey1/.virtualenvs/rooster-d4LzYqiE/lib/python3.7/site-packages/flask_injector.py", line 81, in wrap_fun
    return wrap_class_based_view(fun, injector)
  File "/Users/jacksontoomey1/.virtualenvs/rooster-d4LzYqiE/lib/python3.7/site-packages/flask_injector.py", line 104, in wrap_class_based_view
    flask_restful_api = fun_closure['self']
KeyError: 'self'

Here is an example that fails.

from functools import wraps

from flask import Flask
from flask.views import MethodView
from flask_injector import FlaskInjector


app = Flask(__name__)


def my_wrapper(f):
    @wraps(f)
    def _wrapper(*args, **kwargs):
        return f(*args, **kwargs)
    return _wrapper


class MyView(MethodView):
    decorators = [my_wrapper]

    def get(self):
        return 'Hello'


app.add_url_rule('/', view_func=MyView.as_view('index'))


FlaskInjector(app=app, modules=[])


if __name__ == '__main__':
    app.run()

@JacksonToomey
Copy link
Author

Is there any update on this?

@jstasiak
Copy link
Collaborator

I meant to have a look at this some time ago but I forgot and I don't have time now. Pull requests that fix this (if it's even possible) are welcome though.

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

No branches or pull requests

2 participants