genialis / resolwe

Open source dataflow engine in Django
Apache License 2.0
34 stars 27 forks source link

List inputs in processes incorrectly set if not specified #332

Closed mzganec closed 7 years ago

mzganec commented 7 years ago

A process

- slug: test-list2
  name: Test list2
  requirements:
    expression-engine: jinja
  data_name: 'Test list2'
  version: 0.0.2
  type: data:clustering:hierarchical:sample
  category: analyses
  persistence: TEMP
  description: >
    Test list.
  input:
    - name: genes
      label: Gene subset
      type: list:basic:string
      required: false
  run:
    runtime: polyglot
    language: bash
    program: |
      re-error "Genes: 1{{genes}}2"
      re-progress 1.0

called from resdk by specifying an empty set [] for genes input res.run('test-list2', input={'genes': []}, collections=[6]) correctly returns Genes: 1[]2.

If, however, you call the process by omitting the genes input res.run('test-list2', input={}, collections=[6]) you get Genes: 1"2. Inserting " instead of an empty list [] when an input is not specified is incorrect.

Consequently a Jinja2 check {% if not genes %} in the run section of the process behaves incorrectly as well.

kostko commented 7 years ago

Inserting " instead of an empty list [] when an input is not specified is incorrect

Why? If an input is not specified, it is None (or undefined), not a default-constructed type. I find this behavior correct. Otherwise we need to specify default for each input field.

Consequently a Jinja2 check {% if not genes %} in the run section of the process behaves incorrectly as well

Can you elaborate on that? If the input is not set, not genes should evaluate to True. Are you saying that it evaluates to False?

mzganec commented 7 years ago

If an input is not specified, it is None (or undefined), not a default-constructed type.

If you print it out, for example with re-error as above, you get ". I was expecting to get [].

If the input is not set, not genes should evaluate to True. Are you saying that it evaluates to False?

It evaluates to False if this input is not specified in the input dictionary of the run method, because its value is incorrectly set to ". If this input is specified as [] in the input dictionary of the run method, it evaluates to True.

kostko commented 7 years ago

Printing a value as a string will automatically perform shell quoting. This does not mean that the actual value contains quotes, only if you try to print it it will be quoted before being printed. For that reason other expressions (like not genes) should not be affected as genes is not actually ''.

kostko commented 7 years ago

Can you prepare a test process containing an if expression, which produces incorrect results when no inputs are passed? So without any printing, just an if expression which does exit 1 when incorrect and exit 0 when correct. Then I can reproduce the issue and see what the problem is.

mzganec commented 7 years ago

This works correctly as you suggested. Thanks! Closing.