Skip to content

Report an out-of-range duration as invalid instead of erroring#1512

Open
c-tonneslan wants to merge 1 commit into
python-jsonschema:mainfrom
c-tonneslan:fix-duration-decimal-overflow
Open

Report an out-of-range duration as invalid instead of erroring#1512
c-tonneslan wants to merge 1 commit into
python-jsonschema:mainfrom
c-tonneslan:fix-duration-decimal-overflow

Conversation

@c-tonneslan

Copy link
Copy Markdown

Fixes #1511.

The duration format checker registers raises=isoduration.DurationParsingException, but isoduration parses components with decimal.Decimal, so an extreme value like "P1E1000000D" raises decimal.Overflow (a decimal.DecimalException / ArithmeticError) instead. That escaped the format checker uncaught rather than the instance being reported invalid.

This adds decimal.DecimalException to the raises tuple, so such an instance is treated as an invalid duration (the checker returns False / raises FormatError) rather than propagating a decimal error.

Added a regression test in test_format.py (skipped when isoduration isn't installed). ruff and the format test suite pass. Happy to add a CHANGELOG entry if you'd like one.

Signed-off-by: Charlie Tonneslan <cst0520@gmail.com>
@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 python-jsonschema | 🛠️ Build #33543324 | 📁 Comparing dc9c50e against latest (97c044c)

  🔍 Preview build  

1 file changed
± _modules/jsonschema/_format/index.html

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.

is_duration raises an uncaught decimal.Overflow on a duration with a large exponent

1 participant