Skip to content

Commit c2806ef

Browse files
authored
Try to_dict method when encoding JSON (#799)
1 parent 6ab0661 commit c2806ef

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

logfire/_internal/json_encoder.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,13 @@ def to_json_value(o: Any, seen: set[int]) -> JsonValue:
275275

276276
if isinstance(o, Sequence):
277277
return [to_json_value(item, seen) for item in o] # type: ignore
278+
279+
try:
280+
# Some VertexAI classes have this method. They have no common base class.
281+
# Seems like a sensible thing to try in general.
282+
return to_json_value(o.to_dict(), seen)
283+
except Exception: # currently redundant, but future-proof
284+
pass
278285
except Exception: # pragma: no cover
279286
pass
280287

0 commit comments

Comments
 (0)