You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by ep...@apache.org on 2022/10/18 13:10:39 UTC
[airflow] 23/41: Fix running debuggers inside `airflow tasks test` (#26806)
This is an automated email from the ASF dual-hosted git repository.
ephraimanierobi pushed a commit to branch v2-4-test
in repository https://gitbox.apache.org/repos/asf/airflow.git
commit 9e31a1154a4d9af56bb8b7ec1dd05c3e26dceabf
Author: Ash Berlin-Taylor <as...@apache.org>
AuthorDate: Fri Sep 30 18:46:14 2022 +0100
Fix running debuggers inside `airflow tasks test` (#26806)
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
(cherry picked from commit 029ebacd9cbbb5e307a03530bdaf111c2c3d4f51)
---
airflow/utils/log/secrets_masker.py | 1 +
tests/utils/log/test_secrets_masker.py | 12 ++++++++++++
2 files changed, 13 insertions(+)
diff --git a/airflow/utils/log/secrets_masker.py b/airflow/utils/log/secrets_masker.py
index 4200056abc..17234bf408 100644
--- a/airflow/utils/log/secrets_masker.py
+++ b/airflow/utils/log/secrets_masker.py
@@ -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)
diff --git a/tests/utils/log/test_secrets_masker.py b/tests/utils/log/test_secrets_masker.py
index c07be27bb7..6de30eb574 100644
--- a/tests/utils/log/test_secrets_masker.py
+++ b/tests/utils/log/test_secrets_masker.py
@@ -18,9 +18,11 @@ from __future__ import annotations
import contextlib
import inspect
+import io
import logging
import logging.config
import os
+import sys
import textwrap
import pytest
@@ -363,3 +365,13 @@ class TestRedactedIO:
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"