This is an automated email from the ASF dual-hosted git repository. ash pushed a commit to branch v2-1-test in repository https://gitbox.apache.org/repos/asf/airflow.git
commit 19332cf80b1016ac83536860adee3f7670e24062 Author: Ash Berlin-Taylor <[email protected]> AuthorDate: Tue May 25 12:03:29 2021 +0100 Don't die when masking `log.exception` when there is no exception (#16047) It is possible that `exc_info` can be set, but contain no exception. We shouldn't fail in this case, even if the output doesn't make sense as shown by the test (the `NoneType: None` line is the exception being logged.) (cherry picked from commit 2f776334e30ce9cc2c6a01b377703914acb7139e) --- airflow/utils/log/secrets_masker.py | 2 +- tests/utils/log/test_secrets_masker.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/airflow/utils/log/secrets_masker.py b/airflow/utils/log/secrets_masker.py index 42e0e55..73a2aef 100644 --- a/airflow/utils/log/secrets_masker.py +++ b/airflow/utils/log/secrets_masker.py @@ -155,7 +155,7 @@ class SecretsMasker(logging.Filter): 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 ba88b87..1146bce 100644 --- a/tests/utils/log/test_secrets_masker.py +++ b/tests/utils/log/test_secrets_masker.py @@ -97,6 +97,21 @@ class TestSecretsMasker: """ ) + 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): """
