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
jkomyno committed
Aug 25, 2026 at 14:49 UTC
4ee3ff83bcd57c5358da66aa5f54bd01f64d78fb
2 files changed
+39
-4
python/composio/core/models/_files.py
+9
-4
@@ -1105,10 +1105,15 @@ class FileHelper(WithLogger):
1105
if schema.get("file_uploadable", False):
1106
return leaf(value)
1107
1108
- # Upload-enabled execution historically omits null file values, while
1109
- # disabled execution preserves them for nullable schemas. The active
1110
- # leaf handler owns that distinction.
1111
- if value is None and self._file_uploadable(schema):
1108
+ # Array-only file inputs historically omit null in upload mode even
1109
+ # though null cannot be traversed as an array. Keep that behavior
1110
+ # without treating an optional object that merely contains a nested
1111
+ # file property as a file leaf itself.
1112
+ if (
1113
+ value is None
1114
+ and self._is_array_shaped_schema(schema)
1115
+ and self._file_uploadable(schema)
1116
+ ):
1117
return leaf(value)
1118
1119
uploadable_variant = self._find_uploadable_schema_variant(
python/tests/test_files.py
+30
@@ -779,6 +779,36 @@ class TestFileUploadSubstitutionWithUnionTypes:
779
# None/empty values should be removed
780
assert "fileInput" not in result
781
782
+ def test_substitute_upload_preserves_null_optional_object_with_nested_file(
783
+ self, file_helper, mock_tool
784
+ ):
785
+ """A null container is not itself a file-uploadable leaf."""
786
+ mock_tool.input_parameters = {
787
+ "type": "object",
788
+ "properties": {
789
+ "options": {
790
+ "type": "object",
791
+ "properties": {
792
+ "attachment": {
793
+ "type": "object",
794
+ "file_uploadable": True,
795
+ }
796
+ },
797
+ }
798
+ },
799
+ }
800
+ request = {"options": None}
801
+
802
+ with patch.object(FileUploadable, "from_path") as from_path:
803
+ result = file_helper.substitute_file_uploads(
804
+ tool=mock_tool,
805
+ request=request,
806
+ )
807
+
808
+ assert result is request
809
+ assert result == {"options": None}
810
+ from_path.assert_not_called()
811
+
812
def test_drop_empty_file_uploads_omits_empty_strings_without_uploading(
813
self, file_helper, mock_tool
814
):