Skip to content

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

Open
leandrodamascena wants to merge 1 commit intodevelopfrom
fix/fix-local-resolver
Open

fix(event_handler): sync middleware receives real response in async ASGI context#8089
leandrodamascena wants to merge 1 commit 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
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Apr 2, 2026

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.75%. Comparing base (dafed6a) to head (0c791a7).
⚠️ Report is 1 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #8089      +/-   ##
===========================================
+ Coverage    96.65%   96.75%   +0.10%     
===========================================
  Files          282      282              
  Lines        13798    13817      +19     
  Branches      1103     1103              
===========================================
+ Hits         13336    13369      +33     
+ Misses         339      328      -11     
+ Partials       123      120       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

1 participant