Skip to content

Commit

Permalink
Missing middlewares
Browse files Browse the repository at this point in the history
  • Loading branch information
sheldygg committed Nov 23, 2024
1 parent e6c3007 commit 6d41ea3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion faststream/broker/subscriber/call_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ async def call(
"""Execute wrapped handler with consume middlewares."""
call: AsyncFuncAny = self.handler.call_wrapped

for middleware in chain(self.item_middlewares, _extra_middlewares):
for middleware in chain(self.item_middlewares[::-1], _extra_middlewares):
call = partial(middleware, call)

try:
Expand Down
10 changes: 5 additions & 5 deletions faststream/broker/subscriber/usecase.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ async def process_message(self, msg: MsgType) -> "Response":

# enter all middlewares
middlewares: List[BaseMiddleware] = []
for base_m in self._broker_middlewares:
for base_m in self._broker_middlewares[::-1]:
middleware = base_m(msg)
middlewares.append(middleware)
await middleware.__aenter__()
Expand Down Expand Up @@ -360,14 +360,14 @@ async def process_message(self, msg: MsgType) -> "Response":
stack.enter_context(context.scope("message", message))

# Middlewares should be exited before scope release
for m in middlewares:
for m in middlewares[::-1]:
stack.push_async_exit(m.__aexit__)

result_msg = ensure_response(
await h.call(
message=message,
# consumer middlewares
_extra_middlewares=(m.consume_scope for m in middlewares),
_extra_middlewares=(m.consume_scope for m in middlewares[::-1]),
)
)

Expand All @@ -382,15 +382,15 @@ async def process_message(self, msg: MsgType) -> "Response":
result_msg.body,
**result_msg.as_publish_kwargs(),
# publisher middlewares
_extra_middlewares=(m.publish_scope for m in middlewares),
_extra_middlewares=(m.publish_scope for m in middlewares[::-1]),
)

# Return data for tests
return result_msg

# Suitable handler was not found or
# parsing/decoding exception occurred
for m in middlewares:
for m in middlewares[::-1]:
stack.push_async_exit(m.__aexit__)

if parsing_error:
Expand Down

0 comments on commit 6d41ea3

Please sign in to comment.