Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@miguelgrc
Copy link
Contributor

@miguelgrc miguelgrc commented Feb 3, 2026

Details

Adds support for base64-encoded strings in the Attachment.data field, fixing the "File name too long" error (OSError [Errno 63]) that occurred when users passed base64 strings.

Implementation Strategy:

  • Try file path first
  • Otherwise base64 decode with base64.b64decode(validate=True)
  • On binascii.Error, fall back to treating string as file path for backwards compatibility
  • Decoded bytes are written to temp file and marked for deletion
  • Full backward compatibility maintained - existing file path behavior unchanged

Key Changes:

  • converters.py: Added base64 detection and decoding logic in attachment_to_message()
  • attachment.py: Updated docstring to document base64 string support
  • test_converters.py: Added focused test for base64 string handling

Change checklist

  • User facing
  • Documentation update

Issues

Testing

Unit Tests: All 15 tests passing (14 existing + 1 new)

  • test_attachment_to_message__base64_string - Verifies base64 decoding, temp file creation, content preservation, and cleanup flags
  • ✅ All existing tests pass without modification - confirms backward compatibility

Test Coverage:

  • Base64 string decoding and temp file creation
  • Content integrity after decode
  • Proper delete_after_upload flag setting
  • MIME type inference from file_name
  • Fallback to file path for non-base64 strings

Manual Testing:
Tested with Google ADK use case (base64-encoded images from Gemini API):

import opik
import base64

image_bytes = open("image.png", "rb").read()
base64_string = base64.b64encode(image_bytes).decode("utf-8")

opik.track(
    attachments=[opik.Attachment(data=base64_string, file_name="image.png")]
)

Documentation

Updated:

  • Attachment class docstring now explicitly documents base64 string support

User-facing change: Users can now pass base64-encoded strings directly to Attachment.data without errors.

@miguelgrc miguelgrc requested a review from a team as a code owner February 3, 2026 19:15
@github-actions github-actions bot added python Pull requests that update Python code tests Including test files, or tests related like configuration. Python SDK labels Feb 3, 2026
@miguelgrc miguelgrc force-pushed the miguelg/OPIK-3828-fix-base64-attachment-support branch from d3160c7 to 4370047 Compare February 3, 2026 19:19
@github-actions
Copy link
Contributor

github-actions bot commented Feb 3, 2026

SDK E2E Tests Results

0 tests  ±0   0 ✅ ±0   0s ⏱️ ±0s
0 suites ±0   0 💤 ±0 
0 files   ±0   0 ❌ ±0 

Results for commit c02e21a. ± Comparison against base commit 1d6469d.

♻️ This comment has been updated with latest results.

@miguelgrc miguelgrc force-pushed the miguelg/OPIK-3828-fix-base64-attachment-support branch from 4370047 to 0edf149 Compare February 4, 2026 10:59
@miguelgrc miguelgrc force-pushed the miguelg/OPIK-3828-fix-base64-attachment-support branch 2 times, most recently from bc6a5bf to c02e21a Compare February 4, 2026 12:31
@github-actions
Copy link
Contributor

github-actions bot commented Feb 5, 2026

SDK Unit Tests Results

1 431 tests   1 423 ✅  40s ⏱️
    1 suites      0 💤
    1 files        8 ❌

For more details on these failures, see this check.

Results for commit d211b80.

♻️ This comment has been updated with latest results.

@yaricom
Copy link
Contributor

yaricom commented Feb 6, 2026

Hi @miguelgrc ! Before this PR there was no checks for file existence and it was OK to use imaginary file system paths. Now, we need to fix the tests that fail due to this change to use some temporary file. You can create a test fixture that creates a temporary file with random data and deletes it after test execution. For example:

@pytest.fixture()
def temp_file_15kb():
    file_size = 15 * 1024
    with tempfile.NamedTemporaryFile(delete=True) as f:
        f.write(np.random.bytes(file_size))
        f.flush()

        yield f

In the test you can this fixture as file path: temp_file_15kb.name

You can put this fixture into global tests\conftest.py as it would be useful for other tests as well.

@miguelgrc miguelgrc requested review from a team as code owners February 9, 2026 10:48
@github-actions github-actions bot added documentation Improvements or additions to documentation dependencies Pull requests that update a dependency file java Pull requests that update Java code Frontend Backend Infrastructure typescript *.ts *.tsx TypeScript SDK labels Feb 9, 2026
Add support for base64-encoded strings in the Attachment.data field,
resolving "File name too long" errors when passing base64 strings.

All existing tests pass without modification.

Changes:
- Modified converters.py to detect and decode base64 strings
- Added comprehensive test for base64 string handling
- Updated Attachment docstring to document base64 support
- Maintains full backward compatibility with existing file path behavior

Implements OPIK-3828: Fix base64 attachment support
Changes:
- Raise ValueError for invalid attachment data instead of silent fallback
- Add test for invalid data type validation
- Update existing tests to use valid inputs (real files via fixture)

Non-existent file paths now raise ValueError immediately
instead of being silently passed through (fail-fast approach).
@miguelgrc miguelgrc force-pushed the miguelg/OPIK-3828-fix-base64-attachment-support branch from 188bd94 to 28aeefc Compare February 9, 2026 10:54
@github-actions github-actions bot removed documentation Improvements or additions to documentation dependencies Pull requests that update a dependency file java Pull requests that update Java code Frontend Backend Infrastructure typescript *.ts *.tsx TypeScript SDK labels Feb 9, 2026
@comet-ml comet-ml deleted a comment from baz-reviewer bot Feb 9, 2026
Updated tests to use real temporary files instead of non-existent file paths,
which now fail with the stricter attachment validation that requires data to be
bytes, an existing file path, or valid base64.

Changes:
- Added temp_file_15kb fixture in tests/conftest.py for lightweight test files
- Updated test_attachments_extraction_processor.py to use temp_file_15kb fixture
- Updated test_span_context_manager.py to use temp_file_15kb fixture

All 1431 unit tests now pass.
@miguelgrc miguelgrc force-pushed the miguelg/OPIK-3828-fix-base64-attachment-support branch from 28aeefc to f22f8b0 Compare February 9, 2026 10:56
@miguelgrc miguelgrc merged commit 67b9ec2 into main Feb 9, 2026
112 checks passed
@miguelgrc miguelgrc deleted the miguelg/OPIK-3828-fix-base64-attachment-support branch February 9, 2026 12:26
miguelgrc added a commit that referenced this pull request Feb 12, 2026
* [OPIK-3828] [SDK] Add base64 string support for Attachment.data

Add support for base64-encoded strings in the Attachment.data field,
resolving "File name too long" errors when passing base64 strings.

All existing tests pass without modification.

Changes:
- Modified converters.py to detect and decode base64 strings
- Added comprehensive test for base64 string handling
- Updated Attachment docstring to document base64 support
- Maintains full backward compatibility with existing file path behavior

Implements OPIK-3828: Fix base64 attachment support

* Revision 1: strict validation for attachment data
Changes:
- Raise ValueError for invalid attachment data instead of silent fallback
- Add test for invalid data type validation
- Update existing tests to use valid inputs (real files via fixture)

Non-existent file paths now raise ValueError immediately
instead of being silently passed through (fail-fast approach).

* Revision 2: Fix unit tests to use actual temp files

Updated tests to use real temporary files instead of non-existent file paths,
which now fail with the stricter attachment validation that requires data to be
bytes, an existing file path, or valid base64.

Changes:
- Added temp_file_15kb fixture in tests/conftest.py for lightweight test files
- Updated test_attachments_extraction_processor.py to use temp_file_15kb fixture
- Updated test_span_context_manager.py to use temp_file_15kb fixture

All 1431 unit tests now pass.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Python SDK python Pull requests that update Python code tests Including test files, or tests related like configuration.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants