Skip to content
Closed
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
6 changes: 5 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 string
Expand Down Expand Up @@ -518,7 +519,10 @@ def is_uri_template(instance: object) -> bool:
@_checks_drafts(
draft201909="duration",
draft202012="duration",
raises=isoduration.DurationParsingException,
raises=(
isoduration.DurationParsingException,
decimal.DecimalException,
),
)
def is_duration(instance: object) -> bool:
if not isinstance(instance, str):
Expand Down
8 changes: 8 additions & 0 deletions jsonschema/tests/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ def test_format_checkers_come_with_defaults(self):
with self.assertRaises(FormatError):
checker.check(instance="not-an-ipv4", format="ipv4")

def test_duration_overflow_is_invalid(self):
checker = FormatChecker()
if "duration" not in checker.checkers:
self.skipTest("isoduration is not installed")

with self.assertRaises(FormatError):
checker.check(instance="P1E1000000D", format="duration")

def test_repr(self):
checker = FormatChecker(formats=())
checker.checks("foo")(lambda thing: True) # pragma: no cover
Expand Down