fix: coerce exception code to string or None - #3611
Conversation
ting-hong-shieh
left a comment
There was a problem hiding this comment.
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.
| # Test None code | ||
| err = APIError("message", request, body={"code": None}) | ||
| assert err.code is None | ||
|
|
There was a problem hiding this comment.
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).
|
Confirmed the remaining formatting failure — it's a single extra blank line at end of file, introduced by the new test:
One-liner fix: printf '%s\n' "$(cat tests/test_client.py)" > tests/test_client.pyor just remove the last empty line in your editor and push. |
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.