We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Describe the bug I found an interesting bug: di doesn't work with built-in generics.
class Client: pass class Service: def __init__(self, clients: list[Client]) -> None: self._clients = clients def _get_clients() -> list[Client]: return [Client() for _ in range(3)] def configure_di(app: Sanic) -> None: app.ext.add_dependency(list[Client], _get_clients) app.ext.add_dependency(Service)
It throws the following error:
File "/usr/local/lib/python3.11/site-packages/sanic_ext/extensions/injection/injector.py", line 37, in finalize_injections injection_registry.finalize(app, constant_registry, router_types) File "/usr/local/lib/python3.11/site-packages/sanic_ext/extensions/injection/registry.py", line 42, in finalize constructor.prepare( File "/usr/local/lib/python3.11/site-packages/sanic_ext/extensions/injection/constructor.py", line 111, in prepare raise InitError( sanic_ext.exceptions.InitError: Unable to resolve dependencies for 'Service'. Could not find the following dependencies: - clients: list[src.di.Client]. Make sure the dependencies are declared using ext.injection. See https://sanicframework.org/en/plugins/sanic-ext/injection.html#injecting-services for more details. Not all workers acknowledged a successful startup. Shutting down.
Environment (please complete the following information):
The text was updated successfully, but these errors were encountered:
I found the issue in sanic_ext/extensions/injection/constructor.py:
sanic_ext/extensions/injection/constructor.py
if not isclass(annotation): missing.append((param, annotation)) continue
The condition for list[Client] will always be True. It is necessary to add a new check for built-in generics.
list[Client]
True
Sorry, something went wrong.
Created pull request #263
No branches or pull requests
Describe the bug
I found an interesting bug: di doesn't work with built-in generics.
It throws the following error:
Environment (please complete the following information):
The text was updated successfully, but these errors were encountered: