rest-api: Fix POST error for /api/sys/server and /api/sys/psu_update#271
Open
louis-nexthop wants to merge 5 commits into
Open
rest-api: Fix POST error for /api/sys/server and /api/sys/psu_update#271louis-nexthop wants to merge 5 commits into
louis-nexthop wants to merge 5 commits into
Conversation
…(), and rename common_force_async to async_in_common_executor Signed-off-by: Louis Maliyam <louis@nexthop.ai>
|
This pull request has been imported. If you are a Meta employee, you can view this in D108230434. (Because this pull request was imported automatically, there will not be any future comments.) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #272
get_data_from_generator(request.json())with parsedctx.json_datasince aiohttp >= 3.0.0 no longer returns generator-based couroutine.RequestContextdataclass: thread-safe snapshot of RestAPI request payload, captured before entering the executor thread.@async_web_handler_in_common_executordecorator for request handlers; buildsRequestContexton the event loop and feeds it to the handlers.(self, ctx: RequestContext)and use@async_web_handler_in_common_executor.@common_force_async→@async_in_common_executorfor non-request functions._run_in_common_executor()helper; unify onget_running_loop().Motivation
Calling POST action with JSON data would fail with
TypeError("'coroutine' object is not an iterator"):This is because of the transition from aiohttp 2.3.10 -> aiohttp 3.0.0, where
Request.json()no longer returns a generator-based coroutine (v2.3.10 vs v3.0.0).However,
/api/sys/serverand/api/sys/psu_updateendpoints still rely onget_data_from_generator(request.json())which assumes a generator-based coroutine. So, instead, we should useawait request.json()to get the data.Caveat:
rockoanddunfellstill use aiohttp 2.1.0, as shown here (aiohttp_2.1.0.bb).kirkstoneandmasterusespython3-aiohttpfrommeta-openembedded. As of now:await request.json()should also work on aiohttp 2.1.0 (confirmed with local testing, using python 3.8 + aiohttp 2.1.0)request.can_read_body()does not exist in aiohttp 2.1.0, so it is handled separatelyTest Plan
Before:
After: