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

Skip to content

Fix module run to allow optional path inputs#7163

Merged
bentsherman merged 4 commits into
masterfrom
fix-module-run-optional-path-input
May 21, 2026
Merged

Fix module run to allow optional path inputs#7163
bentsherman merged 4 commits into
masterfrom
fix-module-run-optional-path-input

Conversation

@bentsherman

Copy link
Copy Markdown
Member

Close #7161

This PR adds support for optional file inputs to nextflow module run.

When a path input is not supplied a value at runtime, the ProcessEntryHandler defaults to [] instead of throwing an error. This is needed to allow for optional file inputs which are a common use case.

For legacy processes, one consequence is that missing required files will not be reported until task execution. This is because legacy processes have no way to declare whether a path input is optional.

For typed processes, optional file inputs are declared as Path? and so can be validated prior to task execution. With this PR, a null param value is allowed as long as the input is declared as optional.

@netlify

netlify Bot commented May 20, 2026

Copy link
Copy Markdown

Deploy Preview for nextflow-docs-staging canceled.

Name Link
🔨 Latest commit 6628cbc
🔍 Latest deploy log https://app.netlify.com/projects/nextflow-docs-staging/deploys/6a0f3a68bb5ee10008af7a8c

@jorgee jorgee left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks fine and fixes the issue case. Nothing is blocking from my side just minor comments.

Comment thread modules/nextflow/src/test/groovy/nextflow/script/ProcessEntryHandlerTest.groovy Outdated
@jorgee

jorgee commented May 21, 2026

Copy link
Copy Markdown
Contributor

One comment that come into my mind when reviewing the PR, but out of the scope of the PR. Can we have the same issue with input variables (val) in V1? Nothing in the documentation says that optional parameters are supported. I see a strange case, but not sure if it is done in nf-core modules or if optional parameters are just used for files?

@pditommaso

Copy link
Copy Markdown
Member

Took a closer look — overall this is a clean, surgical change. The downstream wiring is correct: I traced both the [] (v1) and null (v2) returns through TaskProcessor.applyInputContextV2 (lines 1801–1884) and confirmed that null is skipped and re-validated against !param.optional with a clear error message. The Path?isOptional()=true model is correctly leveraged.

One thing worth considering, plus a few nice-to-haves:

Important to consider

The original repro from #7161 (--intervals "") is not actually fixed — only omission is.

The new guard in ProcessEntryHandler.getValueForInputV1 only handles value == null. The reporter's command used --intervals "" (empty string), which means namedArgs.get('intervals') == "" (non-null) → falls through to parseFileInput("")Nextflow.file("") → still errors.

Users naturally write --foo "" on the CLI to signal "no value", so this gap will likely come back as a follow-up bug report. One-liner fix:

if( value == null || (param instanceof FileInParam && value instanceof CharSequence && !value) ) {
    if( param instanceof FileInParam )
        return []
    throw new IllegalArgumentException("Missing required parameter: --${name}")
}

Or, document explicitly in the changelog / docs that the user must omit the flag rather than pass an empty string.

Nice to have

  1. No log signal when v1 silently swallows a missing path input. A typo like --read vs --reads will now surface as a far-downstream task-execution failure with no hint that the root cause was a misspelled flag. Even a log.debug (or throttled log.warn1) noting "path input --${name} not provided, defaulting to empty list" would help post-mortem debugging.

  2. No v1 negative test for non-FileInParam inputs. The new test covers the early-return for FileInParam, but there's no explicit assertion that e.g. ValueInParam still throws. The pre-existing should throw exception for missing required parameter test catches the regression by accident, but doesn't pin the contract of the instanceof FileInParam guard. Strengthening it to assert the exception message would make the contract explicit.

  3. ProcessInput is mocked rather than constructed. It's a simple value object with a 3-arg constructor (name, type, optional) — using a real instance instead of Mock(ProcessInput) { ... } would make the v2 tests more refactor-resistant.

  4. No changelog / docs update. This changes the failure semantics for nextflow module run with missing path inputs — worth a line in changelog.txt and a sentence in the nextflow module run docs.

Follow-up idea (not for this PR)

The PR notes that legacy processes have no way to declare optionality. The recently-merged meta.yml schema validation in #7094 makes ModuleSpec.ModuleParam a natural place to add an optional: true field — so getValueForInputV1 could honor that metadata via paramTypes (extended with an optional flag) and reject truly-required missing inputs while permitting truly-optional ones. Worth a follow-up issue.

@bentsherman bentsherman force-pushed the fix-module-run-optional-path-input branch from 4107dba to 6628cbc Compare May 21, 2026 17:01
@bentsherman

Copy link
Copy Markdown
Member Author

Can we have the same issue with input variables (val) in V1? Nothing in the documentation says that optional parameters are supported. I see a strange case, but not sure if it is done in nf-core modules or if optional parameters are just used for files?

In theory yes, val inputs can also be optional. But in practice they tend to have a default value (0, false, '', etc) which is easy to supply on the command line.

This fix is needed for path inputs because of how the path string is being converted to a file path under the hood, so users need a way to circumvent that. Omitting the option is the simplest solution and also consistent with how optional file params work at the pipeline level

@bentsherman bentsherman merged commit 4fd28fd into master May 21, 2026
22 of 24 checks passed
@bentsherman bentsherman deleted the fix-module-run-optional-path-input branch May 21, 2026 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"nextflow module run" with multiple optional path inputs ?

3 participants