fix(event_handler): sync middleware receives real response in async ASGI context by leandrodamascena · Pull Request #8089 · aws-powertools/powertools-lambda-python · GitHub
Skip to content

fix(event_handler): sync middleware receives real response in async ASGI context#8089

Merged
leandrodamascena merged 2 commits intodevelopfrom
fix/fix-local-resolver
Apr 6, 2026
Merged

fix(event_handler): sync middleware receives real response in async ASGI context#8089
leandrodamascena merged 2 commits intodevelopfrom
fix/fix-local-resolver

Conversation

@leandrodamascena
Copy link
Copy Markdown
Contributor

Issue number: Closes #7981

The fix runs sync middlewares in a separate thread. When the middleware calls next(app), we intercept that call, resolve the async handler on the event loop, and pass the real response back to the thread. This way both request validation (pre-processing) and response validation (post-processing) see the actual data.

Changes

  • Rewrote _wrap_middleware_async in http_resolver.py to use thread-based coordination between sync middlewares and async handlers
  • Removed @pytest.mark.skip from existing async validation test
  • Added tests for async handler response validation (422)
  • Added tests for sync handlers called via ASGI with validation (200 and 422)

User experience

Please share what the user experience looks like before and after this change


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@leandrodamascena leandrodamascena requested a review from a team as a code owner April 2, 2026 21:36
@leandrodamascena leandrodamascena requested a review from hjgraca April 2, 2026 21:36
@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Apr 2, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 2, 2026

@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Apr 6, 2026
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Apr 6, 2026

@leandrodamascena leandrodamascena merged commit 74fbcc5 into develop Apr 6, 2026
17 checks passed
@leandrodamascena leandrodamascena deleted the fix/fix-local-resolver branch April 6, 2026 07:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

event_handlers size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug(HttpResolverLocal): OpenAPIResponseValidationMiddleware is not working as intended

2 participants