Repository: DataBiosphere/toil

Issue:
Toil is not assigning self correctly in CWL workflow step inputs for falsey values
Toil seems to ignore "falsey" values (null, false, 0) when provided as a workflow step input, and instead gets assigned the default value of the step.

I have the following workflow and expects it to give `true` when passing `--input_bool` and `false` if not.

```
$ cat test_bool.cwl
cwlVersion: v1.0
class: Workflow

requirements:
  StepInputExpressionRequirement: {}
  InlineJavascriptRequirement: {}

inputs:
  input_bool:
    type: boolean
    default: False

outputs:
  out:
    type: File
    outputSource: echo/out

steps:
  echo:
    run:
      cwlVersion: v1.0
      class: CommandLineTool
      baseCommand: echo
      inputs:
        str:
          type: string
          default: "UNDEFINED"
          inputBinding:
            position: 1
      outputs:
        out: stdout
      stdout: file.txt
    in:
      str:
        source: input_bool
        valueFrom: ${ return "self is " + self.toString(); }
    out:
      - out
```

This works fine in `cwltool`:
```
$ cwltool test_bool.cwl &> /dev/null && cat file.txt
self is false
$ cwltool test_bool.cwl --input_bool &> /dev/null && cat file.txt
self is true
```

But not using `toil-cwl-runner`:
```
$ toil-cwl-runner test_bool.cwl &> /dev/null && cat file.txt
self is UNDEFINED
$ toil-cwl-runner test_bool.cwl --input_bool &> /dev/null && cat file.txt
self is true
```

It seems like self is assigned the default value of the step input, rather than a boolean with value false as expected. 

This is also true if a workflow passes the value 0 to an input of type `int`. As an example:
```
$ cat test_int.cwl
cwlVersion: v1.0
class: Workflow

requirements:
  StepInputExpressionRequirement: {}
  InlineJavascriptRequirement: {}

inputs:
  input_int:
    type: int

outputs:
  out:
    type: File
    outputSource: echo/out

steps:
  echo:
    run:
      cwlVersion: v1.0
      class: CommandLineTool
      baseCommand: echo
      inputs:
        str:
          type: string
          default: 2
          inputBinding:
            position: 1
      outputs:
        out: stdout
      stdout: file.txt
    in:
      str:
        source: input_int
        valueFrom: ${ return "self is " + self.toString(); }
    out:
      - out
```

Again, `cwltool` does the right thing:
```
cwltool test_int.cwl --input_int 0 &> /dev/null && cat file.txt
self is 0
cwltool test_int.cwl --input_int 10 &> /dev/null && cat file.txt
self is 10
```

But `toil-cwl-runner` gets this wrong:
```
$ toil-cwl-runner test_int.cwl --input_int 0 &> /dev/null && cat file.txt
self is 2
$ toil-cwl-runner test_int.cwl --input_int 10 &> /dev/null && cat file.txt
self is 10
```

This impacts workflows that use the source value to determine what to pass to the next step in the workflow. This results in that some workflows are executed using very different parameters in `toil-cwl-runner` compared to `cwltool`. The cwltool implementation seem to be correct from my understanding of the [CWL specifications](https://www.commonwl.org/v1.0/Workflow#WorkflowStepInput).

Above examples were run using 4.2.0 but I also see this in 4.0.0 and 4.1.0.
```
$ toil-cwl-runner --version
4.2.0
$ uname -a
Linux dockervm 4.15.0-20-generic #21-Ubuntu SMP Tue Apr 24 06:16:15 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
```

┆Issue is synchronized with this [Jira Task](https://ucsc-cgl.atlassian.net/browse/TOIL-599)
┆Issue Number: TOIL-599



Discussion:

Resolving patch:
diff --git a/src/toil/cwl/cwltoil.py b/src/toil/cwl/cwltoil.py
--- a/src/toil/cwl/cwltoil.py
+++ b/src/toil/cwl/cwltoil.py
@@ -404,7 +404,7 @@ def resolve(self) -> Any:
         """
         if self.source:
             result = self.source.resolve()
-            if result:
+            if result is not None:
                 return result
         return self.default
 


Test patch: