Skip to content

docs: log the first retry at INFO in the callback example - #765

Open
tongwentao wants to merge 1 commit into
jd:mainfrom
tongwentao:docs/first-retry-log-level
Open

tongwentao wants to merge 1 commit into
jd:mainfrom
tongwentao:docs/first-retry-log-level

Conversation

@tongwentao

@tongwentao tongwentao commented Oct 22, 2026 •

Copy link
Copy Markdown

The custom before_sleep logging example checks attempt_number < 1, but attempts are numbered from 1. Its INFO branch is therefore unreachable, and every retry logs at WARNING.

Check attempt_number == 1 so the first retry logs at INFO and subsequent retries log at WARNING. The README links to the same documentation source, so both views receive the correction. Library behavior is unchanged. Include a Reno note.

Behavior and review notes

This callback runs before sleeping for a retry, so the example's first callback already has attempt_number == 1. The correction changes the example's choice of log level, not Tenacity's retry count, wait policy, or callback scheduling. Running the exact documentation block checks the advertised INFO-then-WARNING sequence rather than a separately maintained approximation.

Validation on Linux, Python 3.13.5:

  • Executed the exact example from the documentation, intercepting Logger.log: before the correction both events were WARNING; afterward they are INFO then WARNING.
  • poe check: 185 tests and 35 documentation tests passed; strict Sphinx HTML build passed.
  • poe lint and poe mypy: passed.
  • git diff --check: passed.

Prepared and validated with Codex assistance.

@mergify

mergify Bot commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

This branch has not been deployed

No deployments
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.

1 participant