Skip to content

Commit ec1b424

Browse files
committed
fix: Prevent crashes while computing JSON schemas
1 parent 3c432f5 commit ec1b424

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/griffe_pydantic/_internal/dynamic.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ def _process_class(obj: type, cls: Class, *, processed: set[str], schema: bool =
5656
"""Detect and prepare Pydantic models."""
5757
common._process_class(cls)
5858
if schema:
59-
cls.extra[common._self_namespace]["schema"] = common._json_schema(obj)
59+
try:
60+
cls.extra[common._self_namespace]["schema"] = common._json_schema(obj)
61+
except Exception as exc:
62+
# Schema generation can fail and raise Pydantic errors.
63+
_logger.debug("Failed to generate schema for %s: %s", cls.path, exc)
6064
for member in cls.all_members.values():
6165
kind = member.kind
6266
if kind is Kind.ATTRIBUTE:

src/griffe_pydantic/_internal/static.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,11 @@ def _process_class(cls: Class, *, processed: set[str], schema: bool = False) ->
165165
except ImportError:
166166
_logger.debug(f"Could not import class {cls.path} for JSON schema")
167167
return
168-
cls.extra[common._self_namespace]["schema"] = common._json_schema(true_class)
168+
try:
169+
cls.extra[common._self_namespace]["schema"] = common._json_schema(true_class)
170+
except Exception as exc:
171+
# Schema generation can fail and raise Pydantic errors.
172+
_logger.debug("Failed to generate schema for %s: %s", cls.path, exc)
169173

170174
for member in cls.all_members.values():
171175
kind = member.kind

0 commit comments

Comments
 (0)