Skip to content

fix: coerce exception code to string or None - #3611

Open
Rajeev91691 wants to merge 1 commit into
openai:mainfrom
Rajeev91691:fix/exception-code-coercion
Open

fix: coerce exception code to string or None#3611
Rajeev91691 wants to merge 1 commit into
openai:mainfrom
Rajeev91691:fix/exception-code-coercion

Conversation

@Rajeev91691

Copy link
Copy Markdown

Coerce error code inside APIError body to str | None to prevent validation errors with construct_type when the API returns integer codes (e.g. 400). Added unit test in tests/test_client.py.

@Rajeev91691
Rajeev91691 requested a review from a team as a code owner August 13, 2026 18:34

@ting-hong-shieh ting-hong-shieh left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Reviewed b00a48a against #3531. The focused regression passes, and the normalization keeps the public str | None contract intact. One reproducible formatting failure remains below. No API call or external service was used.

Validation snapshot:

  • Focused pytest: 1 passed, 176 deselected.
  • Ruff 0.14.7 check: passed.
  • Ruff 0.14.7 format check: failed because tests/test_client.py would be reformatted.
  • git diff --check: failed at tests/test_client.py:2971.

Comment thread tests/test_client.py
# Test None code
err = APIError("message", request, body={"code": None})
assert err.code is None

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Please remove this extra blank line at EOF. Using the repository-pinned Ruff 0.14.7, ruff format --check src/openai/_exceptions.py tests/test_client.py reports that this file would be reformatted; git diff --check independently reports tests/test_client.py:2971: new blank line at EOF. The focused regression itself passes (1 passed, 176 deselected).

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.

2 participants