-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[OPIK-3828] [SDK] Add base64 string support for Attachment.data #5048
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[OPIK-3828] [SDK] Add base64 string support for Attachment.data #5048
Conversation
d3160c7 to
4370047
Compare
4370047 to
0edf149
Compare
sdks/python/tests/unit/api_objects/attachment/test_converters.py
Outdated
Show resolved
Hide resolved
bc6a5bf to
c02e21a
Compare
SDK Unit Tests Results1 431 tests 1 423 ✅ 40s ⏱️ For more details on these failures, see this check. Results for commit d211b80. ♻️ This comment has been updated with latest results. |
|
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 fIn the test you can this fixture as file path: You can put this fixture into global |
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).
188bd94 to
28aeefc
Compare
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.
28aeefc to
f22f8b0
Compare
* [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.
Details
Adds support for base64-encoded strings in the
Attachment.datafield, fixing the "File name too long" error (OSError [Errno 63]) that occurred when users passed base64 strings.Implementation Strategy:
base64.b64decode(validate=True)binascii.Error, fall back to treating string as file path for backwards compatibilityKey Changes:
converters.py: Added base64 detection and decoding logic inattachment_to_message()attachment.py: Updated docstring to document base64 string supporttest_converters.py: Added focused test for base64 string handlingChange checklist
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 flagsTest Coverage:
delete_after_uploadflag settingfile_nameManual Testing:
Tested with Google ADK use case (base64-encoded images from Gemini API):
Documentation
Updated:
Attachmentclass docstring now explicitly documents base64 string supportUser-facing change: Users can now pass base64-encoded strings directly to
Attachment.datawithout errors.