Repository navigation
Fix airflow info --file-io uploading an empty report - #72707
Conversation
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
left a comment
There was a problem hiding this comment.
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
Co-authored-by: rjgoyln <[email protected]>
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.
|
Thanks @rjgoyln for the careful trace, applied two of the three:
|
|
Hi maintainer, this PR was merged without a milestone set.
|
Backport successfully created: v3-3-testNote: As of Merging PRs targeted for Airflow 3.X In matter of doubt please ask in #release-management Slack channel.
|
…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]>
) (#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]>
airflow info --file-ioreports success and hands back a file.io link, but the file it uploaded isempty. 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 onethat was left empty:
rich only appends to the record buffer while no capture is active
(
Console._write_buffer:if self.record and not self._buffer_index), andcapture()increments_buffer_indexon entry. So the render went into the capture buffer, which was never read, and therecording stayed empty —
export_text()returned"".Fix
Use the capture alone and read it back.
--file-ioshould 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 tostyles=Falseandstripped styles, while
Capture.get()renders them, so keeping the defaultcolor_system="auto"would have put ANSI escape sequences into an uploaded file. Measured on a terminal, the
jsonoutputcarried roughly 5000 bytes of escape codes (20091 → 15168 characters once disabled);
tableandyamlwere affected too.Tests
test_show_info_anonymize_fileiogains an assertion on the body actually handed tohttpx.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 iswhat users were uploading.
test_render_text_stays_plain_on_a_color_terminalsetsFORCE_COLOR=1so rich treats itself as acolour 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=Nonefails the second test; reverting the whole change fails both.Known gap:
--output plainis only partly fixedAirflowConsole.print_as_plain_table(airflow-core/src/airflow/cli/simple_table.py:84) ends in thebuiltin
print(output)rather thanself.print(...), so the tabulated body bypasses the capture andgoes straight to the terminal. With
--output plainthe upload therefore still contains only thesection 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 fixedeither. It is left out deliberately, because
print_as_plain_tableis shared by every command's--output plainand a safe replacement needs four separate flags, each guarding a distinctcorruption:
self.print(output)[team-a, prod]is parsed as rich markup and disappears+ markup=False, highlight=Falseprint(output)report:smile:dailyreport😄dailywithoutemoji=Falseprintdoes not, needingsoft_wrap=TrueThat 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?
Generated-by: Claude Code (Opus 5) following the guidelines