Skip to content

Commit

Permalink
Fix running debuggers inside airflow tasks test (#26806)
Browse files Browse the repository at this point in the history
As part of 2.3.3 we added redaction to output from the tasks test
command, but unfortunately that broke using a debugger with this error:

```
  File "/usr/lib/python3.10/pdb.py", line 262, in user_line
    self.interaction(frame, None)
  File "/home/ash/.virtualenvs/airflow/lib/python3.10/site-packages/pdb.py", line 231, in interaction
    self._cmdloop()
  File "/usr/lib/python3.10/pdb.py", line 322, in _cmdloop
    self.cmdloop()
  File "/usr/lib/python3.10/cmd.py", line 126, in cmdloop
    line = input(self.prompt)
TypeError: 'NoneType' object cannot be interpreted as an integer
```

(ipdb has a similar but different error)

The "fix" is to assign a fileno attribute to the object. `input()` needs
this to write the prompt. It feels like a "bug" that it doesn't work
without it, but as this class is only used in `tasks test` this is a
safe change
  • Loading branch information
ashb authored Sep 30, 2022
1 parent 677df10 commit 029ebac
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions airflow/utils/log/secrets_masker.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ class RedactedIO(TextIO):

def __init__(self):
self.target = sys.stdout
self.fileno = sys.stdout.fileno

def write(self, s: str) -> int:
s = redact(s)
Expand Down
12 changes: 12 additions & 0 deletions tests/utils/log/test_secrets_masker.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@

import contextlib
import inspect
import io
import logging
import logging.config
import os
import sys
import textwrap

import pytest
Expand Down Expand Up @@ -363,3 +365,13 @@ def test_write(self, capsys):
RedactedIO().write(p)
stdout = capsys.readouterr().out
assert stdout == "***"

def test_input_builtin(self, monkeypatch):
"""
Test that when redirect is inplace the `input()` builtin works.
This is used by debuggers!
"""
monkeypatch.setattr(sys, 'stdin', io.StringIO("a\n"))
with contextlib.redirect_stdout(RedactedIO()):
assert input() == "a"

0 comments on commit 029ebac

Please sign in to comment.