Skip to content

3.0.2

Choose a tag to compare

@github-actions github-actions released this 15 Sep 17:10
· 27 commits to main since this release
3.0.2
5c34eb3

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_di wires DI into every broker of the app, not only app.broker.
    FastStream 0.7 apps hold a list of brokers (FastStream(*brokers),
    app.add_broker), and app.broker is only the first. The middleware went onto
    that one, so a FromDI subscriber 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_startup hook that walks
    app.brokers, so a broker added with app.add_broker after setup_di is
    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. FromDI on
    such a message used to die inside modern-di with
    AttributeError: 'NoneType' object has no attribute 'resolve_dependency'. It
    now raises a RuntimeError saying the request container is missing and naming
    the two fixes: call setup_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.