Repository navigation
3.0.2
modern-di-faststream 3.0.2 — DI on every broker
Two fixes to setup_di and FromDI. Both were latent since the FastStream 0.7 bump;
neither changes anything for a single-broker app started the normal way.
Fixes
-
setup_diwires DI into every broker of the app, not onlyapp.broker.
FastStream 0.7 apps hold a list of brokers (FastStream(*brokers),
app.add_broker), andapp.brokeris only the first. The middleware went onto
that one, so aFromDIsubscriber on any other broker failed on its first
message with nothing at setup time pointing at the cause.The middleware is now installed by an
on_startuphook that walks
app.brokers, so a broker added withapp.add_brokeraftersetup_diis
covered too, and a stopped and restarted app does not gain a second copy.
Rationale in
ADR-0002.
(#42, #52) -
A clear error when the DI middleware never ran for a message.
FromDIon
such a message used to die inside modern-di with
AttributeError: 'NoneType' object has no attribute 'resolve_dependency'. It
now raises aRuntimeErrorsaying the request container is missing and naming
the two fixes: callsetup_di(app, container)on the app that owns the broker,
and start the app. (#54, #55)
Downstream
Nothing is required of you. One behaviour is observable in tests: the middleware
now lands on the broker at app startup, not when setup_di returns. A test that
enters TestNatsBroker(broker) without TestApp(app) never runs startup
hooks, so a FromDI subscriber there raises the new RuntimeError instead of
handling the message by accident. Pair them in the same statement, as the docs
have always asked:
async with TestNatsBroker(broker) as br, TestApp(app):
await br.publish(...)Also
- Classifier
Programming Language :: Python :: Free Threading :: 2 - Beta; CI
runs the suite on the free-threaded 3.14t build.