From f44183334fc9c050e176f148461c808992083a37 Mon Sep 17 00:00:00 2001 From: Jarek Potiuk Date: Tue, 7 Dec 2021 22:40:03 +0100 Subject: [PATCH] Fix infinite recursion on redact log (#20039) * Fix infinite recursion on redact log When redact warning log on "unredactable" item is printed, the log entered an infinite recursion, because the item was attempted to be redacted again in the log. This PR converts the item to str() - in the worst case the str converstion will fail and raise exception - but this will be about right - but it will not attempt to redact the item again. Fixes: #19816 * Update airflow/utils/log/secrets_masker.py --- airflow/utils/log/secrets_masker.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/airflow/utils/log/secrets_masker.py b/airflow/utils/log/secrets_masker.py index 6607c399cf9d7..b01f4ce47437e 100644 --- a/airflow/utils/log/secrets_masker.py +++ b/airflow/utils/log/secrets_masker.py @@ -213,11 +213,13 @@ def _redact(self, item: "RedactableItem", name: Optional[str], depth: int) -> "R else: return item # I think this should never happen, but it does not hurt to leave it just in case + # Well. It happened (see https://github.com/apache/airflow/issues/19816#issuecomment-983311373) + # but it caused infinite recursion, so we need to cast it to str first. except Exception as e: log.warning( - "Unable to redact %r, please report this via . " + "Unable to redact %s, please report this via . " "Error was: %s: %s", - item, + repr(item), type(e).__name__, str(e), )