Skip to content
Open
Changes from 1 commit
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
22 changes: 19 additions & 3 deletions langfuse/_task_manager/media_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,9 @@ def _find_and_process_media(
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 @@ -176,6 +174,24 @@ def _process_data_recursively(data: Any, level: int) -> Any:
for key, value in data.items()
}

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

Comment thread
michael-rubel marked this conversation as resolved.
seen.add(id(data))

return _process_data_recursively(data.model_dump(), level + 1)
Comment thread
michael-rubel marked this conversation as resolved.
Outdated

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))

return _process_data_recursively(data.dict(), level + 1)

return data

return _process_data_recursively(data, 1)
Expand Down