fix: keep --format json output free of status preamble - #97
Merged
Conversation
mrt check printed human-readable status lines (Detected: Django migrations, --since/--min-revision/--check-compat notices) to stdout regardless of --format. With --format json this corrupted the output: consumers piping to a JSON parser hit 'Expecting value: line 1 column 1'. The bug was latent for Alembic and became easy to hit now that Django + --check-compat + --format json is a supported combination. Gate all informational console.print calls on fmt == 'table'. Error warnings that precede typer.Exit are unaffected (they abort before any JSON is emitted). Add regression tests for Alembic and Django --check-compat json.
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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.
Summary
Found while verifying the v1.7.0 Django
--check-compatwork before release.mrt checkprinted human-readable status lines to stdout regardless of--format:Detected: Django migrations--since …/--min-revision …notices--check-compat: … enabledWith
--format jsonthese lines prepend the JSON, so any consumer piping to a parser hitsExpecting value: line 1 column 1 (char 0). The bug was latent for Alembic (plain--format jsonprinted no preamble) and becomes easy to trigger now that Django +--check-compat+--format jsonis a supported combination.Fix
Gate all informational
console.printcalls onfmt == "table". Error warnings that precedetyper.Exitare unaffected — they abort before any JSON is emitted.Tests
test_check_compat_json_output_is_pure_json_alembic— regression for the preamble leaktest_check_compat_json_output_is_pure_json_django— Django + compat + json emits parseable JSON with MRT702486 passed locally;
commands/check.pycoverage 90%.Included in the unreleased v1.7.0 (CHANGELOG updated).