Skip to content

fix(media): traverse tuples for media processing - #2144

Open
jcd1991 wants to merge 2 commits into
langfuse:mainfrom
jcd1991:codex/fix-media-tuples
Open

jcd1991 wants to merge 2 commits into
langfuse:mainfrom
jcd1991:codex/fix-media-tuples

Conversation

@jcd1991

@jcd1991 jcd1991 commented Nov 21, 2026 •

Copy link
Copy Markdown

Summary

  • Traverse tuples when discovering media objects for upload.
  • Traverse tuples when resolving media reference strings.
  • Add focused unit coverage for both paths.

Fixes langfuse/langfuse#20462

Verification

tests/unit/test_media_manager.py::test_media_upload_retries_on_retryable_http_status PASSED [ 2%]
tests/unit/test_media_manager.py::test_media_upload_gives_up_on_non_retryable_http_status PASSED [ 5%]
tests/unit/test_media_manager.py::test_find_and_process_media_sse_done_passes_through PASSED [ 7%]
tests/unit/test_media_manager.py::test_find_and_process_media_sse_json_payload_passes_through PASSED [ 10%]
tests/unit/test_media_manager.py::test_find_and_process_media_valid_base64_uri_is_processed PASSED [ 12%]
tests/unit/test_media_manager.py::test_upload_media_sync_rejects_invalid_media
-------------------------------- live log call ---------------------------------
ERROR langfuse:media.py:166 base64_data_uri, or content_bytes and content_type, or file_path must be provided to LangfuseMedia
PASSED [ 15%]
tests/unit/test_media_manager.py::test_find_and_process_media_data_uri_without_comma_passes_through PASSED [ 17%]
tests/unit/test_media_manager.py::test_find_and_process_media_non_base64_data_uri_passes_through PASSED [ 20%]
tests/unit/test_media_manager.py::test_find_and_process_media_sse_in_nested_structure_passes_through PASSED [ 23%]
tests/unit/test_media_manager.py::test_find_and_process_media_in_tuple_queues_upload PASSED [ 25%]
tests/unit/test_media_manager.py::test_find_and_process_media_gemini_inline_data_is_processed PASSED [ 28%]
tests/unit/test_media_manager.py::test_find_and_process_media_gemini_inline_data_camel_case_is_processed PASSED [ 30%]
tests/unit/test_media_manager.py::test_find_and_process_media_gemini_inline_data_non_string_data_passes_through[image-bytes] PASSED [ 33%]
tests/unit/test_media_manager.py::test_find_and_process_media_gemini_inline_data_non_string_data_passes_through[123] PASSED [ 35%]
tests/unit/test_media_manager.py::test_find_and_process_media_gemini_inline_data_non_string_data_passes_through[inline_data_value2] PASSED [ 38%]
tests/unit/test_media_manager.py::test_media_api_calls_do_not_multiply_client_retries[429] PASSED [ 41%]
tests/unit/test_media_manager.py::test_media_api_calls_do_not_multiply_client_retries[503] PASSED [ 43%]
tests/unit/test_media_manager.py::test_media_api_calls_share_one_retry_budget_across_failure_kinds PASSED [ 46%]
tests/unit/test_media.py::test_init_with_base64_data_uri PASSED [ 48%]
tests/unit/test_media.py::test_init_with_content_bytes PASSED [ 51%]
tests/unit/test_media.py::test_init_with_invalid_input
-------------------------------- live log call ---------------------------------
ERROR langfuse:media.py:166 base64_data_uri, or content_bytes and content_type, or file_path must be provided to LangfuseMedia
ERROR langfuse:media.py:166 base64_data_uri, or content_bytes and content_type, or file_path must be provided to LangfuseMedia
ERROR langfuse:media.py:166 base64_data_uri, or content_bytes and content_type, or file_path must be provided to LangfuseMedia
PASSED [ 53%]
tests/unit/test_media.py::test_content_length PASSED [ 56%]
tests/unit/test_media.py::test_content_sha256_hash PASSED [ 58%]
tests/unit/test_media.py::test_reference_string PASSED [ 61%]
tests/unit/test_media.py::test_parse_reference_string PASSED [ 64%]
tests/unit/test_media.py::test_parse_invalid_reference_string PASSED [ 66%]
tests/unit/test_media.py::test_media_reference_is_url_expired[None-False] PASSED [ 69%]
tests/unit/test_media.py::test_media_reference_is_url_expired[not-a-date-False] PASSED [ 71%]
tests/unit/test_media.py::test_media_reference_is_url_expired[2000-01-01T00:00:00+00:00-True] PASSED [ 74%]
tests/unit/test_media.py::test_media_reference_is_url_expired[2999-01-01T00:00:00+00:00-False] PASSED [ 76%]
tests/unit/test_media.py::test_media_reference_is_url_expired[2000-01-01T00:00:00Z-True] PASSED [ 79%]
tests/unit/test_media.py::test_file_handling PASSED [ 82%]
tests/unit/test_media.py::test_nonexistent_file
-------------------------------- live log call ---------------------------------
ERROR langfuse:media.py:166 base64_data_uri, or content_bytes and content_type, or file_path must be provided to LangfuseMedia
PASSED [ 84%]
tests/unit/test_media.py::test_media_reference_fetch_uses_configured_httpx_client PASSED [ 87%]
tests/unit/test_media.py::test_media_reference_fetch_uses_explicit_client PASSED [ 89%]
tests/unit/test_media.py::test_media_reference_fetch_falls_back_to_default_with_multiple_clients
-------------------------------- live log call ---------------------------------
WARNING langfuse:resource_manager.py:102 Multiple Langfuse clients are instantiated; falling back to a default httpx client for LangfuseMediaReference fetches. Pass an explicit client to fetch_bytes/fetch_base64/fetch_data_uri to honor per-client transport settings.
PASSED [ 92%]
tests/unit/test_media.py::test_resolve_media_references_uses_configured_httpx_client PASSED [ 94%]
tests/unit/test_media.py::test_resolve_media_references_in_tuple PASSED [ 97%]
tests/unit/test_media.py::test_init_with_urlsafe_base64_data_uri PASSED [100%]

============================== 39 passed in 0.37s ============================== — 39 passed

  • All checks passed! — passed
  • 609 files already formatted — passed
  • — passed
  • — passed

RetriggerView in GreptileConfidence Score: 4/5

The PR appears safe to merge, with a non-blocking compatibility issue for callers that pass named tuples to reference resolution.

Summary

Adds tuple traversal to media discovery and reference resolution, with focused tests for both paths.

  • Media inside trace tuples is found and queued for upload.
  • Media references inside tuples are replaced with fetched content.

Reviews (1) · Last reviewed commit: "fix(media): traverse tuples for media pr..." · Reviewed by Greptile

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

Comment thread langfuse/media.py Resolved

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python SDK skips media uploads and reference resolution when media is inside tuples

1 participant