Skip to content

fix(core): parse x-total-count header as int - #2559

Merged
remyleone merged 2 commits into
scaleway:mainfrom
tomaionescu:fix/total-count-int
Nov 27, 2026
Merged

remyleone merged 2 commits into
scaleway:mainfrom
tomaionescu:fix/total-count-int

Conversation

@tomaionescu

Copy link
Copy Markdown
Contributor

Community Note

  • Please vote on this pull request by adding a 👍 reaction to the original pull request comment to help the community and maintainers prioritize this request.
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for pull request followers and do not help prioritize the request

Relates #555

Instance list responses (for example list_servers and list_ips) return total_count as a str such as '11', although the field is typed int. So res.total_count == 11 is False and res.total_count - len(res.servers) raises TypeError. The Instance tests already work around it with int(ips.total_count).

The Instance API sends the total in the X-Total-Count header. Since #595, API._request copies 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 with strconv.ParseInt in scw/client.go. A malformed header now raises ValueError instead of passing a string through.

Tested:

  • New test in scaleway-core/tests/test_api.py mocks requests.request with an X-Total-Count: 3 response. It fails on main ('3' != 3) and passes with the fix.
  • Replaying the recorded test_list_server cassette (x-total-count: 11) through InstanceV1API.list_servers now gives 11 as an int.
  • scaleway-core on Python 3.12: ruff format --check, ruff check, mypy --strict, ty check, pyrefly check, pytest (10 passed).
  • CI=true pytest in scaleway (15 passed, 12 skipped) and scaleway-async (7 skipped), same as on main.

Release note for CHANGELOG:

Instance API list responses now return total_count as an int instead of a str.

AI-assisted.

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
remyleone added this pull request to the merge queue Nov 27, 2026
Merged via the queue into scaleway:main with commit dc5278e Nov 27, 2026
1 of 2 checks passed
@remyleone

Copy link
Copy Markdown
Member

Thanks @tomaionescu for your contribution :)

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