tenacity icon indicating copy to clipboard operation
tenacity copied to clipboard

Fix retry_if_exception_message rejecting empty string arguments

Open bysiber opened this issue 9 months ago • 0 comments

Summary

retry_if_exception_message(message="") incorrectly raises TypeError instead of creating a predicate that matches exceptions with empty string representations.

The Bug

The constructor uses Python truthiness checks (if message, elif match) instead of is not None checks. Since empty string "" is falsy:

  • message="" falls through to else and raises TypeError
  • match="" falls through to else and raises TypeError
  • message="", match="foo" silently uses match instead of raising the mutual exclusion error
from tenacity import retry_if_exception_message

# This should match exceptions like Exception() where str(Exception()) == ""
# Instead raises: TypeError: retry_if_exception_message() missing 1 required argument 'message' or 'match'
r = retry_if_exception_message(message="")

The same issue affects retry_if_not_exception_message since it inherits the constructor.

The Fix

Replaced if message / elif match with if message is not None / elif match is not None.

bysiber avatar Feb 20 '26 09:02 bysiber