From b49309936088365e67346d4b5620f972559f0518 Mon Sep 17 00:00:00 2001 From: Kadir Can Ozden <101993364+bysiber@users.noreply.github.com> Date: Fri, 20 Feb 2026 12:20:33 +0300 Subject: [PATCH] Fix retry_if_exception_message rejecting empty string arguments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The truthiness checks (if message, elif match) treat empty string as falsy, so message='' or match='' falls through to the else branch and raises TypeError. These are valid values — an empty message matches exceptions like Exception() where str(exc) == ''. Switched to 'is not None' checks. --- tenacity/retry.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tenacity/retry.py b/tenacity/retry.py index 593b252d..38cbebfa 100644 --- a/tenacity/retry.py +++ b/tenacity/retry.py @@ -198,19 +198,19 @@ def __init__( message: str | None = None, match: None | str | re.Pattern[str] = None, ) -> None: - if message and match: + if message is not None and match is not None: raise TypeError( f"{self.__class__.__name__}() takes either 'message' or 'match', not both" ) # set predicate - if message: + if message is not None: def message_fnc(exception: BaseException) -> bool: return message == str(exception) predicate = message_fnc - elif match: + elif match is not None: prog = re.compile(match) def match_fnc(exception: BaseException) -> bool: