Skip to content

Validate record fields of process record inputs at runtime - #7692

Merged
bentsherman merged 2 commits into
masterfrom
7133-validate-record-input-fields
Sep 29, 2026
Merged

bentsherman merged 2 commits into
masterfrom
7133-validate-record-input-fields

Conversation

@bentsherman

Copy link
Copy Markdown
Member

Close #7133

Type errors are only warnings in nextflow run (full type checking lives in nextflow lint, #7656), and isAssignableFrom treats any two record types as compatible. As a result, a process input declared with a named record type (sample: Sample) accepted any record at runtime, including ones missing required fields.

This PR checks each declared field of the record type when the input is bound, using the same rules destructured record inputs already follow:

  • missing/null non-nullable field → task fails: input field `id` at index 0 cannot be null -- append `?` ...
  • mismatched field type → warning naming the field: invalid argument type for input field `id` at index 0 -- expected a Boolean but got a String

Nested records are checked recursively. Type mismatches stay warnings because a hard error would give false positives at runtime (e.g. GString for String, Long for Integer).

Example (field world is missing):

record MyInput { greeting: String; world: String; language: String }

process HELLO {
    input:
    sample: MyInput
    ...
}

workflow {
    HELLO(channel.of(record(greeting: "world", language: "English")))
}

Before: task runs with world = null. After: the task fails with the error above.

Added a test to DataflowTypesTest. It fails without this change.

Type errors are only reported as warnings by `nextflow run`, so a named record
input (e.g. `sample: Sample`) previously accepted any record. Check each declared
field of the record type: a missing non-nullable field fails the task and a
mismatched field type is reported as a warning, consistent with other typed inputs.

Signed-off-by: Ben Sherman <bentshermann@gmail.com>
@netlify

netlify Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for nextflow-docs canceled.

Name Link
🔨 Latest commit 074fd0b
🔍 Latest deploy log https://app.netlify.com/projects/nextflow-docs/deploys/6abc09c6d869fa00081d2166

@adamrtalbot

Copy link
Copy Markdown
Collaborator

This is good for really early, defensive programming. Making sure no-one accidentally messes up the inputs. For a workflow:

nextflow.enable.types = true

record MyInput {
    greeting: String
    world: String
    language: String
}

process HELLO {
    input:
    sample: MyInput

    output:
    record(greeting: sample.greeting, language: sample.language, complete: file("output.txt"))

    script:
    """
    echo "${sample.greeting} ${sample.world} (${sample.language})" > output.txt
    """
}

workflow {
    sample = channel.of(
        record(greeting: "world", language: "English")
    )
    HELLO(sample)
}
N E X T F L O W  ~  version 26.09.1-edge
Launching `main.nf` [festering_varahamihira] - revision: b6e248a8c7
WARN: Type checking found 1 error(s) -- run `nextflow lint` to inspect them
ERROR ~ Error executing process > 'HELLO (1)'

Caused by:
  [HELLO (1)] input field `world` at index 0 cannot be null -- append `?` to the type annotation to mark it as nullable

Tip: you can replicate the issue by changing to the process work dir and entering the command `bash .command.run`

 -- Check '.nextflow.log' file for details

For AI, I expect this to be pretty powerful to allow it to iterate quickly.

The question is, is this too aggressive for some users? Forcing them to be very strict with records may slow them down.

@bentsherman
bentsherman merged commit 508fe13 into master Sep 29, 2026
24 checks passed
@bentsherman
bentsherman deleted the 7133-validate-record-input-fields branch September 29, 2026 19:18
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.

Validation using records is not working

3 participants