Issue: Dependency Context Not Propagating to Broker in Task Execution
Problem Description
I'm using a fastapi_app fixture along with InMemoryBroker and InmemoryResultBackend from taskiq. The setup works well for the FastAPI app itself, but tasks executed by TaskIQ encounter an error related to missing dependencies.
The issue was resolved by explicitly updating the broker’s dependency overrides using fastapi_app.dependency_overrides. The updated code looks like this:
@pytest.fixture(autouse=True)
def init_taskiq_deps(fastapi_app: FastAPI):
from backend.tkq import broker
taskiq_fastapi.populate_dependency_context(broker, fastapi_app)
for k, v in fastapi_app.dependency_overrides.items():
broker.dependency_overrides.update({k: v})
yield
broker.custom_dependency_context = {}
Suggested Improvement
It would be beneficial if the dependency context setup in populate_dependency_context could propagate fastapi_app overrides automatically to broker.dependency_overrides or if documentation could be expanded to clarify this requirement.
Issue: Dependency Context Not Propagating to Broker in Task Execution
Problem Description
I'm using a
fastapi_app
fixture along withInMemoryBroker
andInmemoryResultBackend
fromtaskiq
. The setup works well for the FastAPI app itself, but tasks executed by TaskIQ encounter an error related to missing dependencies.Here’s a snippet of my
fastapi_app
fixture:And here’s the initialization of the broker:
In
conftest.py
, I also have the following fixture:Issue Observed
Despite setting up the dependency context, task executions still fail with an error indicating missing dependencies. Here’s the error log:
Solution
The issue was resolved by explicitly updating the broker’s dependency overrides using
fastapi_app.dependency_overrides
. The updated code looks like this:Suggested Improvement
It would be beneficial if the dependency context setup in
populate_dependency_context
could propagatefastapi_app
overrides automatically tobroker.dependency_overrides
or if documentation could be expanded to clarify this requirement.