Skip to content

Fix airflow info --file-io uploading an empty report - #72707

Merged
henry3260 merged 4 commits into
apache:mainfrom
Eason09053360:fix-info-file-io-empty-report
Sep 9, 2026
Merged

henry3260 merged 4 commits into
apache:mainfrom
Eason09053360:fix-info-file-io-empty-report

Conversation

@Eason09053360

Copy link
Copy Markdown
Contributor

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:

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?
  • Yes — Claude Code (Opus 5)

Generated-by: Claude Code (Opus 5) following the guidelines

The report was read back from rich's recording buffer, but the render ran
inside a capture, and rich skips the record buffer while a capture is active.
The command therefore uploaded a zero-byte file and reported success, for a
command whose only purpose is producing that report.

The console is built without a color system because the result is written to
a file, where escape codes would be noise rather than formatting.

@rjgoyln rjgoyln left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Root cause and fix both check out - I traced it against rich's source: _write_buffer only records under not self._buffer_index, which capture() increments, so export_text() was guaranteed to come back empty. color_system=None is load-bearing too, since Capture.get() keeps styles where export_text() stripped them.

Three non-blocking notes below: two on the new test (env determinism, fixture hygiene) and one optional on the console construction.
Just my thoughts, feel free to resolve it =).


Drafted-by: Claude Code (Opus 5); reviewed by @rjgoyln before posting

Eason09053360 and others added 2 commits September 10, 2026 00:39
The console only falls back to a fixed width when stdout is not a tty,
so a report generated from a real terminal was laid out at that
terminal's width and long path values were cut off in the uploaded file.
@Eason09053360

Copy link
Copy Markdown
Contributor Author

Thanks @rjgoyln for the careful trace, applied two of the three:

  • TERM pin - applied via the suggestion. Confirmed the gap you described: with the fix reverted, TERM=dumb made the test pass, and TERM unset / xterm-256color made it fail. With the pin it fails under all three.
  • width=200 - applied. Reproduced it: on an 80-column tty the uploaded report had system_path / python_path cut at column 80.
  • cleanup_providers_manager - left as is. test_show_info and test_show_info_anonymize in the same class already go through the full show() path without that fixture, so the new test is not the first one and I'd rather keep the three consistent. Happy to add it to all three if a maintainer prefers.

@rjgoyln rjgoyln left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice !

@henry3260
henry3260 merged commit 90787d5 into apache:main Sep 9, 2026
73 checks passed
@github-actions github-actions Bot added this to the Airflow 3.3.2 milestone Sep 9, 2026
@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Hi maintainer, this PR was merged without a milestone set.
We've automatically set the milestone to Airflow 3.3.2 based on: backport label targeting v3-3-test
If this milestone is not correct, please update it to the appropriate milestone.

This comment was generated by Milestone Tag Assistant.

@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Backport successfully created: v3-3-test

Note: As of Merging PRs targeted for Airflow 3.X
the committer who merges the PR is responsible for backporting the PRs that are bug fixes (generally speaking) to the maintenance branches.

In matter of doubt please ask in #release-management Slack channel.

Status Branch Result
✅ v3-3-test PR Link

aws-airflow-bot pushed a commit to aws-mwaa/upstream-to-airflow that referenced this pull request Sep 9, 2026
…che#72707)

* Fix airflow info --file-io uploading an empty report

The report was read back from rich's recording buffer, but the render ran
inside a capture, and rich skips the record buffer while a capture is active.
The command therefore uploaded a zero-byte file and reported success, for a
command whose only purpose is producing that report.

The console is built without a color system because the result is written to
a file, where escape codes would be noise rather than formatting.

* Update airflow-core/tests/unit/cli/commands/test_info_command.py

Co-authored-by: rjgoyln <[email protected]>

* Pin the uploaded report width so it does not depend on the terminal

The console only falls back to a fixed width when stdout is not a tty,
so a report generated from a real terminal was laid out at that
terminal's width and long path values were cut off in the uploaded file.

---------
(cherry picked from commit 90787d5)

Co-authored-by: Y-C <[email protected]>
Co-authored-by: Eason09053360 <[email protected]>
Co-authored-by: Henry Chen <[email protected]>
Co-authored-by: rjgoyln <[email protected]>
potiuk pushed a commit that referenced this pull request Sep 9, 2026
) (#72832)

* Fix airflow info --file-io uploading an empty report

The report was read back from rich's recording buffer, but the render ran
inside a capture, and rich skips the record buffer while a capture is active.
The command therefore uploaded a zero-byte file and reported success, for a
command whose only purpose is producing that report.

The console is built without a color system because the result is written to
a file, where escape codes would be noise rather than formatting.

* Update airflow-core/tests/unit/cli/commands/test_info_command.py



* Pin the uploaded report width so it does not depend on the terminal

The console only falls back to a fixed width when stdout is not a tty,
so a report generated from a real terminal was laid out at that
terminal's width and long path values were cut off in the uploaded file.

---------
(cherry picked from commit 90787d5)

Co-authored-by: Y-C <[email protected]>
Co-authored-by: Eason09053360 <[email protected]>
Co-authored-by: Henry Chen <[email protected]>
Co-authored-by: rjgoyln <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants