tenacity
tenacity copied to clipboard
Fix retry_if_exception_message rejecting empty string arguments
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 toelseand raisesTypeErrormatch=""falls through toelseand raisesTypeErrormessage="", match="foo"silently usesmatchinstead 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.