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

[Bug] Dependency injection not works with inherited request class #83

Closed
kijk2869 opened this issue May 23, 2022 · 0 comments · Fixed by #84
Closed

[Bug] Dependency injection not works with inherited request class #83

kijk2869 opened this issue May 23, 2022 · 0 comments · Fixed by #84

Comments

@kijk2869
Copy link
Contributor

Describe the bug
Injector does not recognize the inherited request class as Sanic request class.

Screenshots
Not applicable

To Reproduce

from sanic import Sanic, Request as SanicRequest


class InheritedRequest(SanicRequest):
    ...


app = Sanic("TEST_SERVER", request_class=InheritedRequest)


class Something:
    async def execute(self):
        ...

async def get_something(request: InheritedRequest):
    return Something


app.ext.add_dependency(Something, get_something)

app.run(port=5000, dev=True)

Expected behavior
The injector should skip the request parameter, so that the error not occurs.

Environment (please complete the following information):

  • OS: Windows 10
  • Version: Python 3.10 / Sanic 22.3.2 / Sanic-ext 22.3.2

Additional context

  File "C:\Users\<truncated>\lib\site-packages\sanic_ext\extensions\injection\injector.py", line 31, in finalize_injections
    injection_registry.finalize(router_types)
  File "C:\Users\<truncated>\lib\site-packages\sanic_ext\extensions\injection\registry.py", line 32, in finalize
    constructor.prepare(self, allowed_types)
  File "C:\Users\<truncated>\lib\site-packages\sanic_ext\extensions\injection\constructor.py", line 81, in prepare
    raise InitError(
sanic_ext.exceptions.InitError: Unable to resolve dependencies for 'get_something'. Could not find the following dependencies:
  - request: <class '__main__.InheritedRequest'>.
Make sure the dependencies are declared using ext.injection. See https://sanicframework.org/en/plugins/sanic-ext/injection.html#injecting-services for more details.
@kijk2869 kijk2869 changed the title [Bug] [Bug] Dependency injection not works with inherited request class May 23, 2022
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