Unable to wire injections, Flask out of context error
See original GitHub issueI’m hoping this is just because I’m new at this.
I’m developing an application, and currently working on converting to use dependency-injector. I’ve written a container and have been able to get configuration and a data store factory working. However, I’m running into an issue when wiring up injections with a Flask blueprint.
When I follow the documentation and call the function to wire the container, I get a RuntimeError (actually from Flask):
Traceback (most recent call last):
File "c:\source\personal\pydas\src\pydas\__init__.py", line 61, in create_app
app.container.wire(
File "src/dependency_injector/containers.pyx", line 250, in dependency_injector.containers.DynamicContainer.wire
File "C:\Source\Personal\pyDAS\.env\lib\site-packages\dependency_injector\wiring.py", line 238, in wire
if inspect.isfunction(member):
File "C:\Python38\lib\inspect.py", line 169, in isfunction
return isinstance(object, types.FunctionType)
File "C:\Source\Personal\pyDAS\.env\lib\site-packages\werkzeug-2.0.0rc1-py3.8.egg\werkzeug\local.py", line 379, in __get__
obj = instance._get_current_object()
File "C:\Source\Personal\pyDAS\.env\lib\site-packages\werkzeug-2.0.0rc1-py3.8.egg\werkzeug\local.py", line 499, in _get_current_object
return self.__local() # type: ignore
File "C:\Source\Personal\pyDAS\.env\lib\site-packages\flask-1.1.2-py3.8.egg\flask\globals.py", line 38, in _lookup_req_object
raise RuntimeError(_request_ctx_err_msg)
RuntimeError: Working outside of request context.
This typically means that you attempted to use functionality that needed
an active HTTP request. Consult the documentation on testing for
information about how to avoid this problem.
Although it’s from Flask, it is only raised when calling the wire function, passing in the modules to my blueprints. I’ve refactored my code to no longer use current_app
, thinking that might have made an impact. My primary app factory can be found here: https://github.com/bvanfleet/pydas/blob/u/bvanfleet/di.support/src/pydas/__init__.py
Has this ever been encountered before? I tried searching through the other issues, but couldn’t find an obvious answer.
Issue Analytics
- State:
- Created 3 years ago
- Comments:16 (11 by maintainers)
Top GitHub Comments
That’s great to hear, I was just about to report that I had a reproducable project that you could have worked with (sorry I was AFK for too long). Thanks again for catching and fixing this for me!
Thanks! If any other problems - feel free to open an issue.
PyDAS
is a great project btw!