nextflow-io / nextflow

A DSL for data-driven computational pipelines
http://nextflow.io
Apache License 2.0
2.75k stars 628 forks source link

Classes passed to/from subworkflows converted implicitly to channels only during emit, not take #4886

Closed bskubi closed 7 months ago

bskubi commented 7 months ago

Bug report

The nextflow documentation says:

Workflow inputs are always channels by definition. If a basic data type, such as a number, string, list, etc, is provided, it is implicitly converted to a value channel.

However, passing a class as input to a workflow does not implicitly convert it to a channel. Emitting it does.

Expected behavior and actual behavior

When calling println(x.getClass()) where x was a class Foo passed as a workflow input, it would display class groovyx.gpars.dataflow.DataflowBroadcast but it displays class Foo instead.

Steps to reproduce the problem

class Foo {}

workflow sub {
    take:
    foo

    main:
    println(foo.getClass())
}

workflow {
    foo = new Foo()
    sub(foo)
}

Program output

N E X T F L O W ~ version 23.10.1 Launching demo.nf [trusting_baekeland] DSL2 - revision: f032671f38 class Foo

Environment

Additional context

Personally, I think it's the right choice not to implicitly convert anything to a channel in the input or output, but given that Nextflow does convert outputs to a channel, it should probably continue doing so. So the current behavior is only a "bug" in that it doesn't match the documentation. I'd prefer to change the documentation to match current behavior, not the other way around.

If it were easy to extract the class instance from a value channel and use it as a class in the logic of the subworkflow, that would be OK too. Otherwise, such implicit conversions take away a substantial form of control from the writer of the code, create problems by accident when users don't notice this note, and are only helpful to users who do understand this point as minor occasional syntactic sugar.

bentsherman commented 7 months ago

I believe this was corrected a while ago, the "latest" docs are just lagging behind. This will be addressed soon so that the "latest" docs are updated nightly instead of twice yearly

bentsherman commented 7 months ago

Fixed: https://nextflow.io/docs/latest/workflow.html#workflow-inputs