Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion jsonschema/_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from contextlib import suppress
from datetime import date, datetime
from uuid import UUID
import decimal
import ipaddress
import re
import typing
Expand Down Expand Up @@ -524,7 +525,13 @@ def is_uri_template(instance: object) -> bool:
@_checks_drafts(
draft201909="duration",
draft202012="duration",
raises=isoduration.DurationParsingException,
# isoduration parses components with decimal.Decimal, which raises a
# decimal.DecimalException (e.g. Overflow) rather than a
# DurationParsingException on extreme values such as "P1E1000000D".
raises=(
isoduration.DurationParsingException,
decimal.DecimalException,
),
)
def is_duration(instance: object) -> bool:
if not isinstance(instance, str):
Expand Down
12 changes: 12 additions & 0 deletions jsonschema/tests/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,15 @@ def test_repr(self):
repr(checker),
"<FormatChecker checkers=['bar', 'baz', 'foo']>",
)

def test_duration_with_overflowing_exponent_is_invalid(self):
# A duration whose exponent overflows decimal used to raise an uncaught
# decimal.Overflow instead of reporting the instance as invalid.
# See https://github.com/python-jsonschema/jsonschema/issues/1511
try:
import isoduration # noqa: F401
except ImportError:
self.skipTest("isoduration is not installed")
checker = FormatChecker()
with self.assertRaises(FormatError):
checker.check(instance="P1E1000000D", format="duration")
Loading