Skip to content

fix(api-core): handle non-object REST error envelopes - #19254

Open
pradeep-ramola wants to merge 2 commits into
googleapis:mainfrom
pradeep-ramola:fix/api-core-non-object-error-payloads
Open

pradeep-ramola wants to merge 2 commits into
googleapis:mainfrom
pradeep-ramola:fix/api-core-non-object-error-payloads

Conversation

@pradeep-ramola

Copy link
Copy Markdown
  • Opened an issue before writing the code
  • Tests and linters pass
  • Coverage does not decrease: exceptions.py has 100% statement and branch coverage
  • Docs reviewed; the documented exception-return contract is unchanged, so no documentation change is needed

Fixes #19253

Summary

Normalize the top-level REST error payload and its error member before accessing standard fields. A 503 response such as {"error": null} currently raises AttributeError, masking ServiceUnavailable and preventing the normal retry predicate from recognizing the failure.

Fall back to the existing unknown error message when no standard error object is available. Keep valid error dictionaries, structured details, attached responses, HTTP-status exception selection, and the list-wrapper behavior from #18232 unchanged.

Tests

  • Add 36 parameterized cases across both HTTP-error entry points, including retry classification for 429/503 responses. Before the fix: 24 failed, 12 passed.
  • Full unit + asyncio suite on Windows / Python 3.11.9: 2,031 passed, 1 existing skip (known floating-point flaky test, Batch commit throws ServiceUnavailable: 503 Backend Error #866).
  • Repeat with coverage and --cov-fail-under=100: 100% statement and branch coverage for google.api_core.exceptions.
  • Package-wide pinned Ruff 0.14.14 import checks and format checks, plus flake8: pass. Ruff reports the pre-existing I202 noqa warning in test_grpc_helpers_async.py.
  • Independently verify 32 sync/async retry-recovery scenarios for HTTP 429/503 non-object error envelopes: all recover on the second attempt.
  • git diff --check: pass.

No new dependencies, public API changes, or generated files. All HTTP responses are local test objects; no Google Cloud resources or credentials are used.

AI assistance: implementation and local verification used OpenAI Codex.

@pradeep-ramola
pradeep-ramola requested a review from a team as a code owner November 28, 2026 07:35
@google-cla

google-cla Bot commented Nov 28, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request improves error handling in format_http_response_error by safely handling non-object payloads and non-dictionary error fields, preventing potential runtime errors. It also adds comprehensive unit tests to verify these edge cases. The review feedback suggests simplifying the assignment of the error variable to eliminate redundant ternary checks and enhance code readability.

@pradeep-ramola

Copy link
Copy Markdown
Author

I have signed the Google CLA using the commit author email, pradeepramolaa@gmail.com. The current CLA result recognizes my GitHub username but still flags that author email.

The check's official "New Contributors" rescan link opens successfully, but submitting its Rescan button returns HTTP 400 (also reproduced in a browser). Could a maintainer help rerun the CLA check or advise on the remaining account linkage?

The review suggestion has already been addressed and its thread is resolved. I re-ran the api-core unit and asyncio suites on the current commit: 2,031 passed, one skipped. No code changes were needed for this recheck.

This branch has not been deployed

No deployments
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.

google-api-core: non-object REST error members mask HTTP failures with AttributeError

1 participant