Skip to content

fix: keep --format json output free of status preamble - #97

Merged
croc100 merged 1 commit into
mainfrom
fix/json-output-purity
Jul 13, 2026
Merged

fix: keep --format json output free of status preamble#97
croc100 merged 1 commit into
mainfrom
fix/json-output-purity

Conversation

@croc100

@croc100 croc100 commented Jul 13, 2026

Copy link
Copy Markdown
Owner

Summary

Found while verifying the v1.7.0 Django --check-compat work before release.

mrt check printed human-readable status lines to stdout regardless of --format:

  • Detected: Django migrations
  • --since … / --min-revision … notices
  • --check-compat: … enabled

With --format json these lines prepend the JSON, so any consumer piping to a parser hits Expecting value: line 1 column 1 (char 0). The bug was latent for Alembic (plain --format json printed no preamble) and becomes easy to trigger now that Django + --check-compat + --format json is a supported combination.

Fix

Gate all informational console.print calls on fmt == "table". Error warnings that precede typer.Exit are unaffected — they abort before any JSON is emitted.

Tests

  • test_check_compat_json_output_is_pure_json_alembic — regression for the preamble leak
  • test_check_compat_json_output_is_pure_json_django — Django + compat + json emits parseable JSON with MRT702

486 passed locally; commands/check.py coverage 90%.

Included in the unreleased v1.7.0 (CHANGELOG updated).

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.
@croc100
croc100 merged commit 37f296d into main Jul 13, 2026
15 checks passed
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 57.14286% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pytest_mrt/commands/check.py 57.14% 0 Missing and 3 partials ⚠️

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants