Repository navigation
Description
Description
OpenAEV.http_patch() (pyoaev/client.py) always calls result.json() on a successful response. A PATCH to an endpoint that answers 2xx with an empty body (a void Spring endpoint, 200 or 204) therefore raises OpenAEVParsingError: Failed to parse the server message, even though the server applied the update.
This is the failure mode of #370, on PATCH instead of PUT. #381 fixes it in http_put only, so each verb now handles the response body differently:
| Method | Empty 2xx body |
|---|---|
http_post |
returns the requests.Response (JSON is parsed only when Content-Type is application/json) |
http_put (with #381) |
returns {} |
http_patch |
raises OpenAEVParsingError |
Not hit today. No manager sets _update_method = UpdateMethod.PATCH (UpdateMixin defaults to PUT, pyoaev/mixins.py:142-157), and a code search across OpenAEV-Platform finds no direct http_patch caller. It will surface as soon as a manager switches to PATCH, or a collector or injector calls http_patch, against such an endpoint.
Environment
- OS: any (reproduced on macOS 26)
- Version: pyoaev 3.261126.1 (latest release) and
main - Other environment details: N/A, the reproduction uses a local stub server, no OpenAEV needed
Reproducible steps
-
Save this script as
repro_patch.py. The stub answers PATCH like avoidSpring endpoint: 2xx, empty body, noContent-Type.# uv run --no-project --with pyoaev==3.261126.1 python repro_patch.py import threading from http.server import BaseHTTPRequestHandler, HTTPServer from pyoaev.client import OpenAEV class VoidEndpoint(BaseHTTPRequestHandler): def do_PATCH(self): self.rfile.read(int(self.headers["Content-Length"])) self.send_response(int(self.path.rsplit("/", 1)[-1])) self.send_header("Content-Length", "0") self.end_headers() def log_message(self, *args): pass server = HTTPServer(("127.0.0.1", 0), VoidEndpoint) threading.Thread(target=server.serve_forever, daemon=True).start() api = OpenAEV(url=f"http://127.0.0.1:{server.server_port}", token="any-token") for status in (200, 204): try: result = api.http_patch(f"/void/{status}", post_data={"field": "value"}) print(f"{status}: OK, returned {result!r}") except Exception as e: print(f"{status}: BUG: {type(e).__name__}: {e} (cause: {e.__cause__!r})")
-
Run
uv run --no-project --with pyoaev==3.261126.1 python repro_patch.py.
Expected output
http_patch() returns normally on a 2xx with an empty body, as http_put() does with #381:
200: OK, returned {}
204: OK, returned {}
Actual output
200: BUG: OpenAEVParsingError: Failed to parse the server message (cause: JSONDecodeError('Expecting value: line 1 column 1 (char 0)'))
204: BUG: OpenAEVParsingError: Failed to parse the server message (cause: JSONDecodeError('Expecting value: line 1 column 1 (char 0)'))
OpenAEVParsingError is not an OpenAEVHttpError, so on_http_error does not wrap it: callers see a parsing failure for a write that succeeded.
Additional information
Proposed fix: move the body handling of http_put and http_patch into one helper, so a void endpoint behaves the same on both verbs and the next one doesn't need another copy of the guard:
def _parse_json_body(self, result: requests.Response) -> Dict[str, Any]:
if not result.content.strip():
# void endpoints answer 2xx with an empty body
return {}
try:
return result.json()
except Exception as e:
raise exceptions.OpenAEVParsingError(
error_message="Failed to parse the server message"
) from e.strip()also treats a body made only of whitespace (some proxies add a newline) as empty.http_postcan keep itsContent-Typerule: callers may rely on it returning theResponsefor non-JSON content, so changing it would be a breaking change.- Tests: an empty 200 and an empty 204 return
{}on bothhttp_putandhttp_patch; a JSON body is still parsed; a non-empty body that isn't JSON still raisesOpenAEVParsingError.
Activity