Skip to content

v3.40.0 behaviour change with undefined/null variables passed into ref #1911

@kirkrodrigues

Description

@kirkrodrigues

Before v3.40.0, when passing a variable into another variable using the ref attribute, undefined and null variables were treated as empty lists. Now, they seem to be treated as empty strings. Which is the expected behavior?

Taskfile that illustrates the problem
version: "3"

vars:
  EMPTY_LIST_VAR: []
  EMPTY_STR_VAR: ""
  NULL_VAR: null

tasks:
  loop_and_echo_var:
    cmd: >-
      {{range .ECHO_VAR}}
      echo {{.}}
      {{end}

  test1:
    cmds:
      - echo "UNDEFINED_VAR"
      - task: loop_and_echo_var
        vars:
          ECHO_VAR:
            ref: ".UNDEFINED_VAR"

  test2:
    cmds:
      - echo "EMPTY_LIST_VAR"
      - task: loop_and_echo_var
        vars:
          ECHO_VAR:
            ref: ".EMPTY_LIST_VAR"

  test3:
    cmds:
      - echo "EMPTY_STR_VAR"
      - task: loop_and_echo_var
        vars:
          ECHO_VAR:
            ref: ".EMPTY_STR_VAR"

  test4:
    cmds:
      - echo "NULL_VAR"
      - task: loop_and_echo_var
        vars:
          ECHO_VAR:
            ref: ".NULL_VAR"

With task v3.39.0, I get the following output for each task:

> task -t bug-repro-tasks.yaml test1
task: [test1] echo "UNDEFINED_VAR"
UNDEFINED_VAR
> task -t bug-repro-tasks.yaml test2
task: [test2] echo "EMPTY_LIST_VAR"
EMPTY_LIST_VAR
> task -t bug-repro-tasks.yaml test3
task: [test3] echo "EMPTY_STR_VAR"
EMPTY_STR_VAR
task: Failed to run task "test3": template: :1:8: executing "" at <.ECHO_VAR>: range can't iterate over
> task -t bug-repro-tasks.yaml test4
task: [test4] echo "NULL_VAR"
NULL_VAR

With task v3.40.0, I get the following output for each task:

> task -t bug-repro-tasks.yaml test1
task: [test1] echo "UNDEFINED_VAR"
UNDEFINED_VAR
task: Failed to run task "test1": template: :1:8: executing "" at <.ECHO_VAR>: range can't iterate over
> task -t bug-repro-tasks.yaml test2
task: [test2] echo "EMPTY_LIST_VAR"
EMPTY_LIST_VAR
> task -t bug-repro-tasks.yaml test3
task: [test3] echo "EMPTY_STR_VAR"
EMPTY_STR_VAR
task: Failed to run task "test3": template: :1:8: executing "" at <.ECHO_VAR>: range can't iterate over
> task -t bug-repro-tasks.yaml test4
task: [test4] echo "NULL_VAR"
NULL_VAR
task: Failed to run task "test4": template: :1:8: executing "" at <.ECHO_VAR>: range can't iterate over
  • Task version: 3.40.0
  • Operating system: Ubuntu 22.04
  • Experiments enabled: None

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions