Repository navigation
fix: retry once with new credentials after a rejected token - #559
Open
ScribleSean wants to merge 1 commit into
Open
ScribleSean wants to merge 1 commit into
ScribleSean wants to merge 1 commit into
Conversation
A rejected token triggered a re-login followed by a retry that resent the original request body, including the old token, and dropped the headers. The server rejected it again, which triggered another re-login, without limit. Refresh the token and account ID in the body and headers before the retry, pass the headers through, and allow a single retry per call. Fixes webdjoe#558.
This branch has not been deployed
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.
Fixes #558.
When the API rejects a token, the library logs in again and retries. The retry resent the original request body, old token included, and dropped the headers, so it was rejected again and triggered another login. That repeated until Python's recursion limit or a VeSync rate limit.
What changed
All in
src/pyvesync/vesync.py:_with_current_credentials()returns a copy of the body or headers withtoken/tkandaccountID/accountIdreplaced by the manager's current values.async_call_apitakes a keyword-only_reauth_retryflag, and a rejected retry raisesVeSyncTokenErrorinstead of logging in again.The existing
_api_attemptscounter andMAX_API_REAUTH_RETRIESare left as they are.Tests
src/tests/test_reauth_retry.pydrivesasync_call_apithrough a fake session:tk,accountId) are refreshedVeSyncTokenError, with one re-login in totalThe first test fails with
RecursionErrorwithout the fix.pytest src/tests: 383 passed, 3 skipped.ruff checkandruff format --checkare clean.mypyreports the same two errors invesyncthermostat.pyasdev.Notes