From e6c300769541599251a3a89535d107007b5abb2d Mon Sep 17 00:00:00 2001 From: sheldy Date: Sat, 23 Nov 2024 22:02:48 +0100 Subject: [PATCH] Fix middlewares order for publishing scope --- faststream/broker/core/usecase.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/faststream/broker/core/usecase.py b/faststream/broker/core/usecase.py index 7bcf35f708..c02d7ee459 100644 --- a/faststream/broker/core/usecase.py +++ b/faststream/broker/core/usecase.py @@ -342,7 +342,7 @@ async def publish( publish = producer.publish - for m in self._middlewares: + for m in self._middlewares[::-1]: publish = partial(m(None).publish_scope, publish) return await publish(msg, correlation_id=correlation_id, **kwargs) @@ -359,7 +359,7 @@ async def request( assert producer, NOT_CONNECTED_YET # nosec B101 request = producer.request - for m in self._middlewares: + for m in self._middlewares[::-1]: request = partial(m(None).publish_scope, request) published_msg = await request( @@ -370,7 +370,7 @@ async def request( async with AsyncExitStack() as stack: return_msg = return_input - for m in self._middlewares: + for m in self._middlewares[::-1]: mid = m(published_msg) await stack.enter_async_context(mid) return_msg = partial(mid.consume_scope, return_msg)