Skip to content

Fix loadContents for file array in step input (#2339) - #2340

Merged
mr-c merged 1 commit into
common-workflow-language:mainfrom
csgroup-oss:fix/file-array-loadContents
Sep 14, 2026
Merged

mr-c merged 1 commit into
common-workflow-language:mainfrom
csgroup-oss:fix/file-array-loadContents

Conversation

@CGuichard

Copy link
Copy Markdown
Contributor

Closes #2339

I moved the file contents read in a loop to be able to load 1..N files wether the step input is a list or not.

There was already a valid test about loadContents with File array, but it was only checking the loadContents for an input's inputBinding, meanwhile here we are in a different use case with workflow step inputs.

cwltool/cwltool/builder.py

Lines 374 to 385 in baefdcb

if loadContents_sourceline and loadContents_sourceline["loadContents"]:
with SourceLine(
loadContents_sourceline,
"loadContents",
WorkflowException,
debug,
):
try:
with self.fs_access.open(fdatum["location"], "rb") as f2:
fdatum["contents"] = content_limit_respected_read(f2)
except Exception as e:
raise Exception("Reading {}\n{}".format(fdatum["location"], e)) from e

@CGuichard CGuichard changed the title Fix loadContents for file array input (#2339) Fix loadContents for file array in step input (#2339) Aug 21, 2026
@codecov

codecov Bot commented Aug 21, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.26%. Comparing base (1599a14) to head (62f2cb5).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2340      +/-   ##
==========================================
+ Coverage   85.22%   85.26%   +0.03%     
==========================================
  Files          46       46              
  Lines        8622     8624       +2     
  Branches     2020     2021       +1     
==========================================
+ Hits         7348     7353       +5     
+ Misses        809      806       -3     
  Partials      465      465              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@CGuichard
CGuichard force-pushed the fix/file-array-loadContents branch from 98e85b3 to 889394a Compare August 21, 2026 10:18
Comment thread cwltool/workflow_job.py Resolved
@CGuichard
CGuichard force-pushed the fix/file-array-loadContents branch from 889394a to 10174db Compare August 21, 2026 15:01
@CGuichard

Copy link
Copy Markdown
Contributor Author

I improved the tests to cover for the if val.get("contents") is None: partial testing. I added a test that asserts the files are not loaded again if contents is already set. The other test now also check that the loading call the read function.

Comment thread tests/test_load_contents.py Resolved
Comment thread tests/test_load_contents.py Resolved
Comment thread tests/test_load_contents.py Resolved
@mr-c

mr-c commented Sep 12, 2026

Copy link
Copy Markdown
Member

@CGuichard Here is a commit to fix the mypyc build. I guess you didn't check the "Allow edits from maintainers" box?

From de3ca8ee8bfe65d5ed1b3dd0658023a42918ffe1 Mon Sep 17 00:00:00 2001
From: "Michael R. Crusoe" <[email protected]>
Date: Sat, 12 Sep 2026 14:00:34 +0200
Subject: [PATCH] skip test if in mypyc-compiled build.

---
 tests/test_load_contents.py | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/tests/test_load_contents.py b/tests/test_load_contents.py
index 565b2507..c0083042 100644
--- a/tests/test_load_contents.py
+++ b/tests/test_load_contents.py
@@ -4,7 +4,9 @@ import json
 from pathlib import Path
 from unittest.mock import patch
 
-from cwltool.builder import content_limit_respected_read
+import pytest
+
+import cwltool.builder
 from cwltool.main import main
 
 from .util import get_data
@@ -24,6 +26,10 @@ def test_load_contents_file_array(tmp_path: Path) -> None:
     assert data == {"data": [1, 2]}
 
 
+@pytest.mark.skipif(
+    not cwltool.builder.__file__.endswith(".py"),
+    reason="Does not work if in a mypyc-compiled build.",
+)
 def test_load_contents_file_array_for_step_input(tmp_path: Path) -> None:
     """Ensures that a File[] in a step input with loadContents loads each file."""
     params = [
@@ -33,7 +39,8 @@ def test_load_contents_file_array_for_step_input(tmp_path: Path) -> None:
     ]
 
     with patch(
-        "cwltool.workflow_job.content_limit_respected_read", wraps=content_limit_respected_read
+        "cwltool.workflow_job.content_limit_respected_read",
+        wraps=cwltool.builder.content_limit_respected_read,
     ) as mock_read:
         assert main(params) == 0
         assert mock_read.call_count == 2  # Exactly 2 files should be read
@@ -43,6 +50,10 @@ def test_load_contents_file_array_for_step_input(tmp_path: Path) -> None:
     assert data == {"data": [1, 2]}
 
 
+@pytest.mark.skipif(
+    not cwltool.builder.__file__.endswith(".py"),
+    reason="Does not work if in a mypyc-compiled build.",
+)
 def test_load_contents_file_array_for_step_input_with_preloaded_contents(tmp_path: Path) -> None:
     """Ensures that loadContents skips re-reading files whose contents are already set."""
     params = [
@@ -53,7 +64,8 @@ def test_load_contents_file_array_for_step_input_with_preloaded_contents(tmp_pat
     ]
 
     with patch(
-        "cwltool.workflow_job.content_limit_respected_read", wraps=content_limit_respected_read
+        "cwltool.workflow_job.content_limit_respected_read",
+        wraps=cwltool.builder.content_limit_respected_read,
     ) as mock_read:
         assert main(params) == 0
         mock_read.assert_not_called()  # Should not read from disk when contents already present
-- 
2.47.3

@CGuichard
CGuichard force-pushed the fix/file-array-loadContents branch from 10174db to 62f2cb5 Compare September 14, 2026 08:00
@CGuichard

Copy link
Copy Markdown
Contributor Author

@mr-c Unfortunately it seems I don't have the checkbox to allow edit from maintainers because the fork is hosted in an organization (https://github.com/csgroup-oss), and the documentation says "On user-owned forks". I didn't find any way to enable this feature for this PR, so I merged your fix in the commit.

@mr-c mr-c left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you @CGuichard !

@mr-c
mr-c merged commit 5224447 into common-workflow-language:main Sep 14, 2026
47 checks passed
@CGuichard
CGuichard deleted the fix/file-array-loadContents branch September 28, 2026 12:12
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.

Step input array of File with loadContents: true not supported

2 participants