Repository navigation
Cli json pollution 66139 - #66223
Closed
FTS18 wants to merge 4 commits into
Closed
Cli json pollution 66139#66223FTS18 wants to merge 4 commits into
FTS18 wants to merge 4 commits into
Conversation
Contributor
|
Can you check out my comment :) thanks for PR but soon we will already change these things. |
Author
Thanks for the quick feedback, @bugraoz93! Understood. If the transition to |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CLI: Eliminate JSON/YAML output pollution by redirecting logs to stderr (#66139)
This PR resolves the issue where machine-readable CLI outputs (JSON/YAML) were being polluted by log messages (e.g., Alembic migrations, import warnings), making them unparseable by tools like
jq.Problem
When running
airflow dags list -o json, logs were printed tostdoutbefore the JSON payload. This resulted in invalid JSON files and broken pipes when used in automation scripts.Solution: Global Log Redirection
A global redirection strategy is implemented to address log pollution at the architectural level:
airflow/__main__.py, the CLI detects machine-readable output flags (-o json,-o yaml) at the start of execution._setup_cli_logginginairflow/utils/cli.py. This function identifiesStreamHandlers pointing tosys.stdoutand redirects them tosys.stderr.Regression Testing
Added
airflow-core/tests/unit/cli/test_cli_output_pollution.pywhich:airflow.__main__.mainstdoutcontains valid JSON onlystderrCloses / Related Issues