Skip to content

Commit

Permalink
Don't die when masking log.exception when there is no exception (ap…
Browse files Browse the repository at this point in the history
…ache#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 2f77633)
  • Loading branch information
ashb authored and kaxil committed Jun 2, 2021
1 parent d20eaa8 commit e24040d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion airflow/utils/log/secrets_masker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 15 additions & 0 deletions tests/utils/log/test_secrets_masker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down

0 comments on commit e24040d

Please sign in to comment.