diff --git a/airflow/utils/log/secrets_masker.py b/airflow/utils/log/secrets_masker.py index 42e0e553aa68c..73a2aef3ef797 100644 --- a/airflow/utils/log/secrets_masker.py +++ b/airflow/utils/log/secrets_masker.py @@ -155,7 +155,7 @@ def filter(self, record) -> bool: if k in self._record_attrs_to_ignore: continue record.__dict__[k] = self.redact(v) - if record.exc_info: + if record.exc_info and record.exc_info[1] is not None: exc = record.exc_info[1] # I'm not sure if this is a good idea! exc.args = (self.redact(v) for v in exc.args) diff --git a/tests/utils/log/test_secrets_masker.py b/tests/utils/log/test_secrets_masker.py index ba88b87a8b009..1146bce2e0be1 100644 --- a/tests/utils/log/test_secrets_masker.py +++ b/tests/utils/log/test_secrets_masker.py @@ -97,6 +97,21 @@ def test_exception(self, logger, caplog): """ ) + def test_exception_not_raised(self, logger, caplog): + """ + Test that when ``logger.exception`` is called when there is no current exception we still log. + + (This is a "bug" in user code, but we shouldn't die because of it!) + """ + logger.exception("Err") + + assert caplog.text == textwrap.dedent( + """\ + ERROR Err + NoneType: None + """ + ) + @pytest.mark.xfail(reason="Cannot filter secrets in traceback source") def test_exc_tb(self, logger, caplog): """