Skip to content
Open
Changes from 2 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
58 changes: 50 additions & 8 deletions langfuse/_task_manager/media_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,9 @@
max_levels = 10

def _process_data_recursively(data: Any, level: int) -> Any:
if id(data) in seen or level > max_levels:
if level > max_levels:
return data
Comment thread
michael-rubel marked this conversation as resolved.

seen.add(id(data))

if isinstance(data, LangfuseMedia):
self._process_media(
media=data,
Expand Down Expand Up @@ -168,13 +166,57 @@
return copied

if isinstance(data, list):
return [_process_data_recursively(item, level + 1) for item in data]
if id(data) in seen:
return data

seen.add(id(data))

try:
return [_process_data_recursively(item, level + 1) for item in data]
finally:
seen.discard(id(data))

if isinstance(data, dict):
return {
key: _process_data_recursively(value, level + 1)
for key, value in data.items()
}
if id(data) in seen:
return data

seen.add(id(data))

try:
return {
key: _process_data_recursively(value, level + 1)
for key, value in data.items()
}
finally:
seen.discard(id(data))

if (
hasattr(data, "__pydantic_fields__")
and hasattr(data, "model_dump")
and callable(data.model_dump)
):
# Pydantic v2 BaseModel
if id(data) in seen:
return data

Check failure on line 201 in langfuse/_task_manager/media_manager.py

View check run for this annotation

Claude / Claude Code Review

Pydantic model_dump/dict exceptions can break user code

The new Pydantic v2/v1 branches call `data.model_dump()` (line 187) and `data.dict()` (line 202) with no exception handling, so a model whose serializer raises (e.g. a `@field_serializer` that raises, `arbitrary_types_allowed` with unserializable fields, or unresolved forward references) will now propagate the exception out of `_find_and_process_media` → `_process_media_in_attribute` → `_process_media_and_apply_mask` into user code. Pre-PR such models fell through to `return data` and were absor
Comment thread
michael-rubel marked this conversation as resolved.
seen.add(id(data))

try:
return _process_data_recursively(data.model_dump(), level + 1)
finally:
seen.discard(id(data))

if hasattr(data, "dict") and callable(data.dict) and hasattr(data, "__fields__"):
# Pydantic v1 BaseModel
if id(data) in seen:
return data

seen.add(id(data))

try:
return _process_data_recursively(data.dict(), level + 1)
finally:
seen.discard(id(data))

return data

Expand Down