{"action":"created","issue":{"url":"https://api.github.com/repos/alecthomas/flask_injector/issues/14","repository_url":"https://api.github.com/repos/alecthomas/flask_injector","labels_url":"https://api.github.com/repos/alecthomas/flask_injector/issues/14/labels{/name}","comments_url":"https://api.github.com/repos/alecthomas/flask_injector/issues/14/comments","events_url":"https://api.github.com/repos/alecthomas/flask_injector/issues/14/events","html_url":"https://github.com/alecthomas/flask_injector/issues/14","id":122099499,"number":14,"title":"KeyError: 'class_args' when testing with class-based views","user":{"login":"stevenhair","id":5742331,"avatar_url":"https://avatars.githubusercontent.com/u/5742331?v=3","gravatar_id":"","url":"https://api.github.com/users/stevenhair","html_url":"https://github.com/stevenhair","followers_url":"https://api.github.com/users/stevenhair/followers","following_url":"https://api.github.com/users/stevenhair/following{/other_user}","gists_url":"https://api.github.com/users/stevenhair/gists{/gist_id}","starred_url":"https://api.github.com/users/stevenhair/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stevenhair/subscriptions","organizations_url":"https://api.github.com/users/stevenhair/orgs","repos_url":"https://api.github.com/users/stevenhair/repos","events_url":"https://api.github.com/users/stevenhair/events{/privacy}","received_events_url":"https://api.github.com/users/stevenhair/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-12-14T18:17:09Z","updated_at":"2016-03-31T16:30:53Z","closed_at":"2016-03-07T03:55:00Z","body":"When running unittest with class-based views under Python 3.5 with flask_injector 0.6.2, I get the following error:\r\n\r\n```\r\nError\r\nTraceback (most recent call last):\r\n  File \"/Users/shair/repos/flask-injection-bug/tests.py\", line 14, in setUp\r\n    FlaskInjector(app=app, modules=[configure])\r\n  File \"/Users/shair/.virtualenvs/flask-injection-bug/lib/python3.5/site-packages/flask_injector.py\", line 221, in __init__\r\n    process_dict(container, injector)\r\n  File \"/Users/shair/.virtualenvs/flask-injection-bug/lib/python3.5/site-packages/flask_injector.py\", line 244, in process_dict\r\n    d[key] = wrap_fun(value, injector)\r\n  File \"/Users/shair/.virtualenvs/flask-injection-bug/lib/python3.5/site-packages/flask_injector.py\", line 63, in wrap_fun\r\n    class_args = fun_closure['class_args']\r\nKeyError: 'class_args'\r\n```\r\n\r\nHere is code to reproduce the error:\r\n\r\napp.py:\r\n```python\r\nfrom flask import Flask\r\nfrom flask.views import View\r\nfrom flask_injector import FlaskInjector\r\nfrom injector import inject\r\n\r\napp = Flask(__name__)\r\n\r\nclass Message(object):\r\n    def __init__(self, message):\r\n        self.message = message\r\n    def __str__(self):\r\n        return self.message\r\n\r\nclass IndexView(View):\r\n    @inject(message=Message)\r\n    def __init__(self, message):\r\n        super(IndexView, self).__init__()\r\n        self.message = message\r\n\r\n    def dispatch_request(self):\r\n        return str(self.message)\r\n\r\n\r\nclass ConfigureBinder(object):\r\n    def __init__(self, message):\r\n        self.message = message\r\n\r\n    def configure_injector(self, binder):\r\n        binder.bind(Message, to=Message(self.message))\r\n\r\napp.add_url_rule('/', view_func=IndexView.as_view('index'))\r\n\r\nconfigure = ConfigureBinder('hello').configure_injector\r\nFlaskInjector(app=app, modules=[configure])\r\n\r\nif __name__ == '__main__':\r\n    app.run(debug=True)\r\n```\r\n\r\ntests.py:\r\n```python\r\nfrom unittest import TestCase\r\nfrom flask_injector import FlaskInjector\r\nfrom app import app, ConfigureBinder\r\n\r\nclass TestApp(TestCase):\r\n\r\n    def setUp(self):\r\n        app.testing = True\r\n        configure = ConfigureBinder('testing').configure_injector\r\n        FlaskInjector(app=app, modules=[configure])\r\n\r\n    def test_message(self):\r\n        response = app.test_client().get('/')\r\n        self.assertIn('testing', str(response.data))\r\n```\r\n\r\nThe problem seems to lie in injecting multiple times. Possibly related to https://github.com/alecthomas/flask_injector/issues/6?\r\n\r\nUpdate: The offending line was indeed introduced in the fix for https://github.com/alecthomas/flask_injector/issues/6: https://github.com/alecthomas/flask_injector/commit/57fddc270020ab4c046b2e559ee8b122d71a7dca#diff-76d5d260b4726f4ecf4f78cba40a6597R50\r\n\r\nUpdate 2: [Here is root offending line](https://github.com/alecthomas/flask_injector/blob/master/flask_injector.py#L115). The problem is that class_args is not passed into `injector.create_object`, so [we don't get a `class_args` property from `fun.__closure__`  in `wrap_class_based_view`](https://github.com/alecthomas/flask_injector/blob/master/flask_injector.py#L63)."},"comment":{"url":"https://api.github.com/repos/alecthomas/flask_injector/issues/comments/204010723","html_url":"https://github.com/alecthomas/flask_injector/issues/14#issuecomment-204010723","issue_url":"https://api.github.com/repos/alecthomas/flask_injector/issues/14","id":204010723,"user":{"login":"stevenhair","id":5742331,"avatar_url":"https://avatars.githubusercontent.com/u/5742331?v=3","gravatar_id":"","url":"https://api.github.com/users/stevenhair","html_url":"https://github.com/stevenhair","followers_url":"https://api.github.com/users/stevenhair/followers","following_url":"https://api.github.com/users/stevenhair/following{/other_user}","gists_url":"https://api.github.com/users/stevenhair/gists{/gist_id}","starred_url":"https://api.github.com/users/stevenhair/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stevenhair/subscriptions","organizations_url":"https://api.github.com/users/stevenhair/orgs","repos_url":"https://api.github.com/users/stevenhair/repos","events_url":"https://api.github.com/users/stevenhair/events{/privacy}","received_events_url":"https://api.github.com/users/stevenhair/received_events","type":"User","site_admin":false},"created_at":"2016-03-31T16:30:53Z","updated_at":"2016-03-31T16:30:53Z","body":"No, I completely agree with you. Injecting multiple times doesn't really make sense, which I figured out after spending more time with flask_injector/injector. I was actually going to close https://github.com/alecthomas/flask_injector/pull/15, but @alecthomas merged it in before I got around to closing it.\r\n\r\nI agree that some sort of warning or exception would be probably be better and promote better project structure."}}