Eason09053360 opened a new pull request, #72707:
URL: https://github.com/apache/airflow/pull/72707
`airflow info --file-io` reports success and hands back a file.io link, but
the file it uploaded is
empty. The command exists only to produce that report, so every link shared
from it — typically in a
bug report — points at a blank file.
## Cause
`AirflowInfo.render_text()` enabled two different rich mechanisms at once
and read back from the one
that was left empty:
```python
console = AirflowConsole(record=True) # recording: print as usual, keep a
copy
with console.capture(): # capture: divert output into a
buffer
self.show(output=output, console=console)
return console.export_text() # read the recording
```
rich only appends to the record buffer while no capture is active
(`Console._write_buffer`: `if self.record and not self._buffer_index`), and
`capture()` increments
`_buffer_index` on entry. So the render went into the capture buffer, which
was never read, and the
recording stayed empty — `export_text()` returned `""`.
## Fix
Use the capture alone and read it back. `--file-io` should not echo the
whole report to the terminal,
so capture is the mechanism that matches the intent; recording is not.
The console is also built with `color_system=None`. `export_text()` defaults
to `styles=False` and
stripped styles, while `Capture.get()` renders them, so keeping the default
`color_system="auto"`
would have put ANSI escape sequences into an uploaded file. Measured on a
terminal, the `json` output
carried roughly 5000 bytes of escape codes (20091 → 15168 characters once
disabled); `table` and
`yaml` were affected too.
## Tests
- `test_show_info_anonymize_fileio` gains an assertion on the body actually
handed to `httpx.post`.
The test previously only checked that the returned link was printed, which
is why an empty upload
went unnoticed. Reverting the fix makes it fail with `assert '3.4.0' in
''` — that empty string is
what users were uploading.
- `test_render_text_stays_plain_on_a_color_terminal` sets `FORCE_COLOR=1` so
rich treats itself as a
colour terminal, then asserts the rendered report contains no escape
sequences. Without the
environment variable the assertion would pass regardless, since pytest's
stdout is not a tty.
Reverting only `color_system=None` fails the second test; reverting the
whole change fails both.
## Known gap: `--output plain` is only partly fixed
`AirflowConsole.print_as_plain_table`
(`airflow-core/src/airflow/cli/simple_table.py:84`) ends in the
builtin `print(output)` rather than `self.print(...)`, so the tabulated body
bypasses the capture and
goes straight to the terminal. With `--output plain` the upload therefore
still contains only the
section headers (measured: 124 characters captured, 16180 written to stdout).
This is not a regression from this PR — that path uploaded `""` before — but
it is not fully fixed
either. It is left out deliberately, because `print_as_plain_table` is
shared by every command's
`--output plain` and a safe replacement needs four separate flags, each
guarding a distinct
corruption:
| Replacement | Result |
| --- | --- |
| `self.print(output)` | `[team-a, prod]` is parsed as rich markup and
disappears |
| `+ markup=False, highlight=False` | byte-identical to `print(output)` |
| `report:smile:daily` | becomes `report😄daily` without `emoji=False` |
| narrow terminal | rich wraps where `print` does not, needing
`soft_wrap=True` |
That belongs in its own change against `simple_table.py`, with its own
coverage for each flag.
---
##### Was generative AI tooling used to co-author this PR?
- [X] Yes — Claude Code (Opus 5)
Generated-by: Claude Code (Opus 5) following [the
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]