Skip to content

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

fix(python): preserve null nested file containers

jkomyno4ee3ff83bcd5
diff --git a/python/composio/core/models/_files.py b/python/composio/core/models/_files.py
index 0746c0ea6..87616c4df 100644
--- a/python/composio/core/models/_files.py
+++ b/python/composio/core/models/_files.py
@@ -1105,10 +1105,15 @@ class FileHelper(WithLogger):
if schema.get("file_uploadable", False):
return leaf(value)
- # Upload-enabled execution historically omits null file values, while
- # disabled execution preserves them for nullable schemas. The active
- # leaf handler owns that distinction.
- if value is None and self._file_uploadable(schema):
+ # Array-only file inputs historically omit null in upload mode even
+ # though null cannot be traversed as an array. Keep that behavior
+ # without treating an optional object that merely contains a nested
+ # file property as a file leaf itself.
+ if (
+ value is None
+ and self._is_array_shaped_schema(schema)
+ and self._file_uploadable(schema)
+ ):
return leaf(value)
uploadable_variant = self._find_uploadable_schema_variant(
diff --git a/python/tests/test_files.py b/python/tests/test_files.py
index ef27e5ffd..bdefd38ad 100644
--- a/python/tests/test_files.py
+++ b/python/tests/test_files.py
@@ -779,6 +779,36 @@ class TestFileUploadSubstitutionWithUnionTypes:
# None/empty values should be removed
assert "fileInput" not in result
+ def test_substitute_upload_preserves_null_optional_object_with_nested_file(
+ self, file_helper, mock_tool
+ ):
+ """A null container is not itself a file-uploadable leaf."""
+ mock_tool.input_parameters = {
+ "type": "object",
+ "properties": {
+ "options": {
+ "type": "object",
+ "properties": {
+ "attachment": {
+ "type": "object",
+ "file_uploadable": True,
+ }
+ },
+ }
+ },
+ }
+ request = {"options": None}
+
+ with patch.object(FileUploadable, "from_path") as from_path:
+ result = file_helper.substitute_file_uploads(
+ tool=mock_tool,
+ request=request,
+ )
+
+ assert result is request
+ assert result == {"options": None}
+ from_path.assert_not_called()
+
def test_drop_empty_file_uploads_omits_empty_strings_without_uploading(
self, file_helper, mock_tool
):