Skip to content

fix: return the error instead of dereferencing a None response on transport failures#564

Open
somethingnew2-0 wants to merge 1 commit into
okta:masterfrom
somethingnew2-0:fix/none-response-attributeerror
Open

fix: return the error instead of dereferencing a None response on transport failures#564
somethingnew2-0 wants to merge 1 commit into
okta:masterfrom
somethingnew2-0:fix/none-response-attributeerror

Conversation

@somethingnew2-0

Copy link
Copy Markdown

Summary

The generated API methods raise AttributeError: 'NoneType' object has no attribute 'status' on any transport-level failure, instead of returning the error in their (data, response, error) result tuple.

Root cause

In openapi/templates/api.mustache (so every generated okta/api/*_api.py method), after execute() returns, the response is dereferenced before the error is checked:

response, response_body, error = await self._request_executor.execute(request, ...)

if response_body == '' or response.status == 204:   # response can be None here
    ...
else:
    response_body = response_body.encode('utf-8')
    if error:                                        # error only checked here
        ...

RequestExecutor.execute() returns (None, None, error) on failure, and HTTPClient.send_request returns (None, None, None, error) for any aiohttp.ClientError / asyncio.TimeoutError. So a dropped/reset connection (e.g. a ServerDisconnectedError from reusing a pooled keep-alive the server has closed) or a socket timeout yields a None response with the error set — and response.status raises before the code ever inspects error.

Because it lives in the template, it affects every generated list_* / get_* / etc. method.

Fix

Add an early guard that returns the error before the dereference, mirroring the existing create_request error handling:

if response is None:
    if <ReturnType> is Success:
        return (None, error)
    else:
        return (None, None, error)

Only the null-response (transport-failure) path changes — it now returns the error in the tuple as documented, instead of raising. HTTP-error handling (a non-None response carrying an error) is untouched.

Notes

  • This is the template change only. The generated okta/api/*_api.py need to be regenerated with the pinned openapi-generator-cli 7.7.0 to propagate the fix; I wasn't able to run the JAR generation locally, so I've left that to the maintainers' pipeline. Happy to regenerate and/or add a regression test if you'd prefer it folded into this PR.
  • Related to Generated code contains nonsensical runtime type comparison + wrong return type annotations #487 (same template / generated methods; this is a separate defect in the post-execute response handling).

🤖 Generated with Claude Code

… API template

The generated API methods evaluate `response_body == '' or response.status == 204`
before checking `error`. On a transport-level failure (dropped/reset connection,
timeout) the request executor returns a None response with the error set, so
`response.status` raises `AttributeError: 'NoneType' object has no attribute
'status'` instead of returning the error in the result tuple.

Guard the dereference with an early `if response is None:` that returns the
error, mirroring the existing create_request error handling. Only the
null-response (transport) path changes; HTTP-error handling is unchanged.

Regenerate okta/api/*_api.py via openapi-generator 7.7.0 to propagate.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant