You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ContextRepo.get returns None for a key nobody set, so when the DI middleware did not run for a message the user sees modern-di's internals fail on the next line:
AttributeError: 'NoneType' object has no attribute 'resolve_dependency'
Nothing in that message points at this package, at setup_di, or at app startup.
When it happens
FromDI is used on an app where setup_di was never called.
The app was never started, so the on_startup hook that installs the middleware (fix: install the DI middleware on every broker, on startup #52) did not run. The common form is a test that enters TestNatsBroker(broker) without TestApp(app); the modern-di docs already warn about that pairing, but the error itself does not.
Before #52 this was also what a subscriber on any broker but the first produced (#42).
Proposal
Check for None in Dependency.__call__ and raise a RuntimeError that says the request container is missing for this message and names the two fixes: call setup_di(app, container) on the app that owns the broker, and start the app (pair the test broker with TestApp in tests).
One failing test first, in tests/test_faststream_di.py, for each of the two triggers above.
What
Dependency.__call__reads the request container out of FastStream'sContextRepo:ContextRepo.getreturnsNonefor a key nobody set, so when the DI middleware did not run for a message the user sees modern-di's internals fail on the next line:Nothing in that message points at this package, at
setup_di, or at app startup.When it happens
FromDIis used on an app wheresetup_diwas never called.on_startuphook that installs the middleware (fix: install the DI middleware on every broker, on startup #52) did not run. The common form is a test that entersTestNatsBroker(broker)withoutTestApp(app); the modern-di docs already warn about that pairing, but the error itself does not.Before #52 this was also what a subscriber on any broker but the first produced (#42).
Proposal
Check for
NoneinDependency.__call__and raise aRuntimeErrorthat says the request container is missing for this message and names the two fixes: callsetup_di(app, container)on the app that owns the broker, and start the app (pair the test broker withTestAppin tests).One failing test first, in
tests/test_faststream_di.py, for each of the two triggers above.