Skip to content

Commit 62ad4c5

Browse files
fix(octopus): count a GraphQL body of data null as a failure for the log gate, and correct its comment
A body of data null with no errors key returns None to the caller, which then reports the query as failed, but the gate treated it as a success and logged a repeat briefly without the request. Count a missing or null data value as a failure. The comment also claimed every gated failure returns no data; a partial error returned with data under ignore_errors is logged in full too, so say so. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent ffd84e4 commit 62ad4c5

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

‎apps/predbat/octopus.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2394,9 +2394,9 @@ def log_request_beside_failure():
23942394
# Process response (which reads the text)
23952395
response_body = await self.async_read_response_retry(response, url, ignore_errors=ignore_errors)
23962396
body_text = str(response_body)
2397-
# A failure is anything the code below will not return data for: a bad status, an errors key, or a
2398-
# body that is missing (unreadable JSON, a rate limit) or has no data
2399-
failed = response.status != 200 or not isinstance(response_body, dict) or "errors" in response_body or "data" not in response_body
2397+
# Logged in full with its request: a bad status, a body that is missing (unreadable JSON, a rate limit)
2398+
# or has no data, or any errors key - even a partial error returned with data when ignore_errors is set
2399+
failed = response.status != 200 or not isinstance(response_body, dict) or "errors" in response_body or response_body.get("data") is None
24002400
if failed:
24012401
log_request_beside_failure()
24022402
self.log_gate.log(

‎apps/predbat/tests/test_octopus_logging.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ async def test_octopus_logging(my_predbat):
139139

140140
# A status 200 with no usable body (unreadable JSON, a rate limit) or no data is a failure too: the request and
141141
# the response are logged in full beside it, even when they repeat
142-
for bad_body, context in [(None, "test-no-body"), ({"other": 1}, "test-no-data")]:
142+
for bad_body, context in [(None, "test-no-body"), ({"other": 1}, "test-no-data"), ({"data": None}, "test-null-data")]:
143143
api.async_read_response_retry = AsyncMock(return_value=bad_body)
144144
await api.async_graphql_query("query { empty }", context, returns_data=True)
145145
log_lines.clear()

0 commit comments

Comments
 (0)