feat(event-handler): add _registered_api_adapter_async() internal building block#8157
Conversation
…lding block - Add async counterpart to _registered_api_adapter() - Detects if route handler result is a coroutine using inspect.iscoroutine() - Awaits async handlers; passes sync handlers through unchanged - _to_response() remains sync (CPU-bound, no async benefit) - Move import inspect to top-level imports (consistent with file style) - Nothing calls this in the resolve chain yet — internal building block only Closes aws-powertools#8135 Part of parent: aws-powertools#3934 Next step: aws-powertools#8137 (public resolve_async()) will wire this in Signed-off-by: hirenkumar-n-dholariya <hirenkumarnd@gmail.com>
|
Thanks a lot for your first contribution! Please check out our contributing guidelines and don't hesitate to ask whatever you need. |
leandrodamascena
left a comment
There was a problem hiding this comment.
Hey @hirenkumar-n-dholariya, thanks for working on this!
I see a few things that need to be addressed before we can move forward:
Rebase needed: PR #8138 was merged into develop. That PR extracted all async event handler logic into a dedicated file: aws_lambda_powertools/event_handler/middlewares/async_utils.py. Your branch doesn't have this change yet, so you'll need to rebase on top of current develop.
Move the function to async_utils.py: Given that async_utils.py now exists as the home for async event handler internals (wrap_middleware_async, _run_sync_middleware_in_thread, etc.), _registered_api_adapter_async() should live there too, not in api_gateway.py. This keeps things consistent with the refactoring direction. Take a look at the file and you'll see the pattern.
Tests are missing: The checklist says "Tests are added" but only api_gateway.py was modified. The issue #8135 explicitly asks for unit tests covering sync, async, and mixed handler scenarios. Please add those.
Let me know if you have any questions. Happy to help!
…utils.py refactor(event-handler): move _registered_api_adapter_async to async_utils.py Per maintainer feedback on aws-powertools#8157 - function belongs in async_utils.py alongside other async event handler internals (wrap_middleware_async, _run_sync_middleware_in_thread, etc.) Signed-off-by: hirenkumar-n-dholariya <hirenkumarnd@gmail.com>
…utils.py Per maintainer feedback on aws-powertools#8157 - function belongs in async_utils.py alongside other async event handler internals (wrap_middleware_async, _run_sync_middleware_in_thread, etc.) Signed-off-by: hirenkumar-n-dholariya <hirenkumarnd@gmail.com>
Tests cover sync handler, async handler, and mixed scenarios as required by issue aws-powertools#8135 Signed-off-by: hirenkumar-n-dholariya <hirenkumarnd@gmail.com>
…utils.py Per maintainer feedback on aws-powertools#8157 - function belongs in async_utils.py alongside other async event handler internals (wrap_middleware_async, _run_sync_middleware_in_thread, etc.) Signed-off-by: hirenkumar-n-dholariya <hirenkumarnd@gmail.com>
|
Hey @leandrodamascena, thanks for the detailed feedback, really appreciate it! I have addressed all three points:
|



Summary
Add
_registered_api_adapter_async()as the async counterpart to the existing_registered_api_adapter(), placed inasync_utils.pyalongside other async event handler internals.Changes
_registered_api_adapter_async()toasync_utils.py:Requestobject if handler declares one (same as sync version)Depends()parameters (same as sync version)inspect.iscoroutine()_to_response()(sync, CPU-bound — stays sync)api_gateway.py— function now lives inasync_utils.pyRelated issues
fixes #8135, closes #3934
Acknowledgment
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.