Repository navigation
fix(core): parse x-total-count header as int - #2559
Merged
Merged
Conversation
Legacy APIs such as Instance return the total in the X-Total-Count header. _request copied the raw header string into the JSON body, so list responses had total_count as a str although the field is typed int. Convert it to int before injecting it.
remyleone
approved these changes
Nov 27, 2026
Member
|
Thanks @tomaionescu for your contribution :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Community Note
Relates #555
Instance list responses (for example
list_serversandlist_ips) returntotal_countas astrsuch as'11', although the field is typedint. Sores.total_count == 11isFalseandres.total_count - len(res.servers)raisesTypeError. The Instance tests already work around it withint(ips.total_count).The Instance API sends the total in the
X-Total-Countheader. Since #595,API._requestcopies that header into the JSON body, and the generated unmarshal functions pass it through unchanged, so the header string ends up in the response object.This PR converts the header with
int()before injecting it, as the Go SDK does withstrconv.ParseIntinscw/client.go. A malformed header now raisesValueErrorinstead of passing a string through.Tested:
scaleway-core/tests/test_api.pymocksrequests.requestwith anX-Total-Count: 3response. It fails on main ('3' != 3) and passes with the fix.test_list_servercassette (x-total-count: 11) throughInstanceV1API.list_serversnow gives11as anint.ruff format --check,ruff check,mypy --strict,ty check,pyrefly check,pytest(10 passed).CI=true pytestin scaleway (15 passed, 12 skipped) and scaleway-async (7 skipped), same as on main.Release note for CHANGELOG:
AI-assisted.