taskiq-python / taskiq

Distributed task queue with full async support
MIT License
694 stars 44 forks source link

Dependency injection using `Annotated` fails with `from __future__ import annotations` #265

Closed itssimon closed 6 months ago

itssimon commented 6 months ago

When using the Annotated syntax for Taskiq dependencies and having the from __future__ import annotations import at the top of the file, dependency injection doesn't work. An error like below will be thrown:

TypeError: my_task() missing 1 required positional argument: 'my_dep'

I can imagine that this may be expected, so I'd suggest adding a note in the documentation so people don't waste as much time debugging this like I just did :)

Otherwise, maybe there is a clue in FastAPI on how to make it work even with the import from __future__?

s3rius commented 6 months ago

Since the algorithm we implemented in the taskiq-dependencies is completely different to fastapi's DI, there would be no hints for fixing it. But I will debug this issue.

s3rius commented 6 months ago

Now everything should work fine with from __future__ import annotations for python versions >= 3.10. Please update the taskiq-dependencies package to version 1.5.0 and verify.

If that works for you, consider closing the issue.

itssimon commented 6 months ago

That works. Thank you!