From 91a30f111eed0d05ce529babf364b43ad2146b6f Mon Sep 17 00:00:00 2001 From: Jaroslaw Potiuk Date: Sat, 4 Dec 2021 18:28:32 +0100 Subject: [PATCH 1/2] 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 --- 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..30efe43564927 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, + item.repr(), type(e).__name__, str(e), ) From a700ebe645f3a4458aee89b431da62b2cb5677e6 Mon Sep 17 00:00:00 2001 From: Ash Berlin-Taylor Date: Tue, 7 Dec 2021 11:13:23 +0000 Subject: [PATCH 2/2] Update airflow/utils/log/secrets_masker.py Co-authored-by: Tzu-ping Chung --- airflow/utils/log/secrets_masker.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/airflow/utils/log/secrets_masker.py b/airflow/utils/log/secrets_masker.py index 30efe43564927..b01f4ce47437e 100644 --- a/airflow/utils/log/secrets_masker.py +++ b/airflow/utils/log/secrets_masker.py @@ -219,7 +219,7 @@ def _redact(self, item: "RedactableItem", name: Optional[str], depth: int) -> "R log.warning( "Unable to redact %s, please report this via . " "Error was: %s: %s", - item.repr(), + repr(item), type(e).__name__, str(e), )