Skip to content

rest-api: Fix POST error for /api/sys/server and /api/sys/psu_update#271

Open
louis-nexthop wants to merge 5 commits into
facebook:heliumfrom
nexthop-ai:fix-rest-api-post-error
Open

rest-api: Fix POST error for /api/sys/server and /api/sys/psu_update#271
louis-nexthop wants to merge 5 commits into
facebook:heliumfrom
nexthop-ai:fix-rest-api-post-error

Conversation

@louis-nexthop

@louis-nexthop louis-nexthop commented Jun 11, 2026

Copy link
Copy Markdown

Description

Fixes #272

  1. Fix POST handler error: replace get_data_from_generator(request.json()) with parsed ctx.json_data since aiohttp >= 3.0.0 no longer returns generator-based couroutine.
  2. Add RequestContext dataclass: thread-safe snapshot of RestAPI request payload, captured before entering the executor thread.
  3. Add @async_web_handler_in_common_executor decorator for request handlers; builds RequestContext on the event loop and feeds it to the handlers.
  4. Migrate all common_endpoint.py handlers to (self, ctx: RequestContext) and use @async_web_handler_in_common_executor.
  5. Rename @common_force_async@async_in_common_executor for non-request functions.
  6. Extract _run_in_common_executor() helper; unify on get_running_loop().

Motivation

Calling POST action with JSON data would fail with TypeError("'coroutine' object is not an iterator"):

root@bmc-oob:~# curl -s -X POST \
  -H "Content-Type: application/json" \
  -d "{\"action\":\"power-on\"}" \
  http://localhost:8080/api/sys/server
{"Information": {"reason": "TypeError(\"'coroutine' object is not an iterator\")"}, "Actions": [], "Resources": []}

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/server and /api/sys/psu_update endpoints still rely on get_data_from_generator(request.json()) which assumes a generator-based coroutine. So, instead, we should use await request.json() to get the data.

Caveat:

  • rocko and dunfell still use aiohttp 2.1.0, as shown here (aiohttp_2.1.0.bb).
  • kirkstone and master uses python3-aiohttp from meta-openembedded. As of now:
Yocto branch Pinned commit (yocto_repos.sh) aiohttp evidence
lf-kirkstone 91c406079 3.8.1 python3-aiohttp_3.8.1.bb
lf-master ea1e8642b 3.13.5 python3-aiohttp_3.13.5.bb
  • 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 separately

Test Plan

Before:

root@bmc-oob:~# python3 -c "import aiohttp; print(aiohttp.__version__)"
3.13.5
root@bmc-oob:~# curl -s -X POST \
  -H "Content-Type: application/json" \
  -d "{\"action\":\"power-on\"}" \
  http://localhost:8080/api/sys/server
{"Information": {"reason": "TypeError(\"'coroutine' object is not an iterator\")"}, "Actions": [], "Resources": []}

After:

root@bmc-oob:~# python3 -c "import aiohttp; print(aiohttp.__version__)"
3.13.5
root@bmc-oob:~# curl -s -X POST \
  -H "Content-Type: application/json" \
  -d "{\"action\":\"power-on\"}" \
  http://localhost:8080/api/sys/server
{"result": "failure", "reason": "already on"}
  • /redfish/v1/Chassis/1/Sensors which has dependency on @async_in_common_executor still work:
root@bmc-oob:~# curl http://localhost:8080/redfish/v1/Chassis/1/Sensors
{"@odata.type": "#SensorCollection.SensorCollection", "Name": "Chassis sensors", "Members@odata.count": 0, "Members": [], "@odata.id": "/redfish/v1/Chassis/1/Sensors"}

@meta-cla meta-cla Bot added the CLA Signed label Jun 11, 2026
@meta-codesync

meta-codesync Bot commented Jun 11, 2026

Copy link
Copy Markdown

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.)

@louis-nexthop louis-nexthop changed the title rest-api: Fix POST error for /api/sys/server and /api/sys/psu_update. rest-api: Fix POST error for /api/sys/server and /api/sys/psu_update Jun 11, 2026
@louis-nexthop louis-nexthop marked this pull request as ready for review June 11, 2026 06:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rest API: POST action with JSON data fails with TypeError("'coroutine' object is not an iterator")

1 participant