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

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.73%. Comparing base (2b95d7f) to head (e58c97e).
⚠️ Report is 1 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #8089      +/-   ##
===========================================
+ Coverage    96.63%   96.73%   +0.10%     
===========================================
  Files          283      283              
  Lines        13862    13881      +19     
  Branches      1111     1111              
===========================================
+ Hits         13395    13428      +33     
+ Misses         342      331      -11     
+ Partials       125      122       -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.

@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