Skip to content

fix: guard validation diagnostics against broken repr - #89

Merged
disafronov merged 1 commit into
mainfrom
fix/safe-validation-repr
Oct 25, 2026
Merged

disafronov merged 1 commit into
mainfrom
fix/safe-validation-repr

Conversation

@disafronov

Copy link
Copy Markdown
Owner

Invalid extra containing an object whose repr raises (or returns a non-string) currently aborts SchemaLogger before the main record is emitted. This contradicts the README's contract that invalid data is dropped and reported separately without raising from the logging call.

Add a private safe repr helper for diagnostic fields, preserving ordinary repr output and substituting a constant <unrepresentable value> when repr fails. The fallback does not format the object or exception again. Public API, strict type checks, schema projection, and fatal schema-configuration behavior are unchanged.

Add eight regression cases covering raising and non-string repr for wrong types, unknown fields, empty schemas, and invalid list elements. They verify preservation of valid fields, rejection of invalid fields, main-record-before-ERROR ordering, aggregation, and JSON string diagnostics.

Validation:

  • All eight regression cases fail on the original implementation and pass with the fix.
  • UV_CACHE_DIR=/tmp/uv-cache make all on Python 3.14.4: 228 tests passed; 100% statement and branch coverage; Black, isort, Flake8, mypy, Bandit, and Vulture passed.
  • git diff --cached --check passed.
  • Other Python versions are covered by the repository's CI matrix; not run locally.

Signed-off-by: Dmitrii Safronov <zimniy@cyberbrain.cc>
@disafronov
disafronov force-pushed the fix/safe-validation-repr branch from 36509c7 to 0aa25be Compare October 25, 2026 21:06
@disafronov
disafronov merged commit 192fbed into main Oct 25, 2026
12 checks passed
@disafronov
disafronov deleted the fix/safe-validation-repr branch October 25, 2026 21:08
@disafronov

Copy link
Copy Markdown
Owner Author

🎉 This PR is included in version 1.0.3-rc.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant