Skip to content

Commit 07d2e54

Browse files
authored
Handle missing attributes in _custom_object_schema (#597)
1 parent b7d8372 commit 07d2e54

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

logfire/_internal/json_schema.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import re
2121
import uuid
2222
from collections import deque
23+
from contextlib import suppress
2324
from decimal import Decimal
2425
from enum import Enum
2526
from functools import lru_cache
@@ -350,9 +351,13 @@ def _properties(properties: dict[str, Any], seen: set[int]) -> JsonDict:
350351

351352

352353
def _custom_object_schema(obj: Any, datatype_name: str, keys: Iterable[str], seen: set[int]) -> JsonDict:
354+
properties: dict[str, Any] = {}
355+
for key in keys:
356+
with suppress(Exception):
357+
properties[key] = getattr(obj, key)
353358
return {
354359
'type': 'object',
355360
'title': obj.__class__.__name__,
356361
'x-python-datatype': datatype_name,
357-
**_properties({key: getattr(obj, key) for key in keys}, seen),
362+
**_properties(properties, seen),
358363
}

0 commit comments

Comments
 (0)