Skip to content

Add max_retries and retry_wait_seconds settings so a caller can turn the automatic retries off - #51

Merged
baraline merged 4 commits into
mainfrom
feat/configurable-retries
Nov 23, 2026
Merged

baraline merged 4 commits into
mainfrom
feat/configurable-retries

Conversation

@baraline

@baraline baraline commented Nov 23, 2026 •

Copy link
Copy Markdown
Owner

Problem

Every network-facing call that hits a transient failure (network fault or 5xx) makes up to three attempts, three seconds apart, and decorators fix this policy at import time. A caller that already retries at its own level, such as a scheduler whose next pass repeats a failed job, cannot turn this off. A call that fails then takes up to three attempts, each with its own timeout, before the caller hears about it, and a deadline the caller sets around the call is hard to choose.

Fix

  • New max_retries and retry_wait_seconds settings on both clients, on GLPITokenManager and GLPIV1Session, and as GLPI_MAX_RETRIES / GLPI_RETRY_WAIT_SECONDS for from_env.
  • max_retries counts the retries after the first attempt. The default 2 keeps the current three attempts, and 0 disables retrying, so a failing call raises after exactly one request. retry_wait_seconds is the pause between attempts (default 3 seconds).
  • The policy is read per instance: a retried(retry_on) decorator in the new _retry.py builds the tenacity loop from the instance's settings. It covers the v2 verbs, the v1 session helpers and OAuth token acquisition. Each call site still decides which errors are retried, so the retried set is unchanged. The final error is re-raised as itself, never as tenacity.RetryError.
  • Invalid values (a negative or non-integer max_retries, a negative retry_wait_seconds) raise GlpiValidationError.
  • The sync twin is regenerated with unasync_build.py (one new token rule: AsyncRetrying -> Retrying).

Behaviour is unchanged unless a setting is passed.

Tests

test_retry_settings.py on both trees covers:

  • max_retries=0 sends one request per verb;
  • the default makes three attempts, and max_retries counts the retries after the first;
  • a 4xx is still not retried;
  • the configured wait separates the attempts, and the default wait is three seconds;
  • the setting reaches a v1 helper, the v1 initSession and the token manager, and the client passes it to these;
  • from_env reads it;
  • bad values are rejected.

An autouse fixture now zeroes the default wait in tests. It replaces the monkeypatches on the old decorators.

Locally, ruff check, mypy glpi_python_client, unasync_build.py --check and the sphinx -W build pass, and so do the test files this branch touches (218 passed). The full suite and the coverage gate run in CI.

Overlaps with other open PRs

Suggested merge order: #50, #51, #52, #53. After each merge I rebase the next branch: the conflicts are the CHANGELOG.md entries, plus one import line in _v1_session.py for #51.

🤖 Generated with Claude Code

baraline and others added 2 commits November 23, 2026 00:49
…n turn the automatic retries off, with the default keeping three attempts three seconds apart.

The retry policy was fixed at import time on the v2 verbs, the v1 session helpers and the OAuth token manager. A per-client retrying wrapper now reads the setting on every call; which errors are retried is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…r_attempt mention in a test docstring.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov-commenter

codecov-commenter commented Nov 23, 2026 •

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 92.72727% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 98.11%. Comparing base (e6b5164) to head (4988fb4).

Files with missing lines Patch % Lines
...pi_python_client/_async/clients/commons/_config.py 77.77% 4 Missing ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #51      +/-   ##
==========================================
- Coverage   98.16%   98.11%   -0.06%     
==========================================
  Files          96       97       +1     
  Lines        3823     3875      +52     
==========================================
+ Hits         3753     3802      +49     
- Misses         70       73       +3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

baraline and others added 2 commits November 23, 2026 09:31
…he async module and its generated sync twin.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@baraline
baraline merged commit ac11353 into main Nov 23, 2026
7 checks passed
@baraline
baraline deleted the feat/configurable-retries branch November 23, 2026 08:44
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