Skip to content

Unreachable code in before_log reached #511

Description

@zdebra

Hello, I've reached code that is marked as unreachable in before_log function:

import logging

from tenacity import RetryError, Retrying, before_log

logging.basicConfig(level=logging.DEBUG, format="%(asctime)s - %(levelname)s - %(message)s")
logger = logging.getLogger(__name__)


def f():
    try:
        for attempt in Retrying(
            before=before_log(logger, logging.DEBUG),
        ):
            with attempt:
                raise Exception("hello")
    except RetryError as exc:
        exc.reraise()


f()

This code sample produces:

2025-01-28 15:11:42,725 - DEBUG - Starting call to '<unknown>', this is the 72232nd time calling it.
2025-01-28 15:11:42,725 - DEBUG - Starting call to '<unknown>', this is the 72233rd time calling it.
2025-01-28 15:11:42,725 - DEBUG - Starting call to '<unknown>', this is the 72234th time calling it.
2025-01-28 15:11:42,725 - DEBUG - Starting call to '<unknown>', this is the 72235th time calling it.
2025-01-28 15:11:42,725 - DEBUG - Starting call to '<unknown>', this is the 72236th time calling it.
2025-01-28 15:11:42,725 - DEBUG - Starting call to '<unknown>', this is the 72237th time calling it.

This is because retry_state.fn is probably not being set here.

Python 3.9.19 & tenacity 9.0.0.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions