Skip to content

Calling parent task with templating bug #1876

@ameergituser

Description

@ameergituser
  • Task version: v3.39.2
  • Operating system: Ubuntu 24.04.1 LTS
  • Experiments enabled: No

Use case

A child task (included taskfile task) which can either call its task or a parent task. The behavior is determined based on a variable using template conditional logic.

Example Taskfiles

.
├── child
│   └── Taskfile.yml
└── Taskfile.yml

Child Taskfile

# https://taskfile.dev

version: '3'

tasks:
  hello:
    cmds:
      - task: work
      - task: :work
      - task: '{{if .CALL_PARENT_TASK}}:work{{else}}work{{end}}'


  work:
    cmds:
      - echo "hello from child!"

Parent Taskfile

# https://taskfile.dev

version: '3'

includes:
  child:
    taskfile: ./child/Taskfile.yml
    dir: ./child
    internal: true

tasks:
  test1:
    cmds:
      - task: child:hello


  test2:
    cmds:
      - task: child:hello
        vars: {CALL_PARENT_TASK: true}


  work:
    cmds:
      - echo "hello from parent!"

Output

Running the parent Taskfile task test1 always works as expected:

task test1
task: [child:work] echo "hello from child!"
hello from child!
task: [work] echo "hello from parent!"
hello from parent!
task: [child:work] echo "hello from child!"
hello from child!

However, running the parent task task test2 always fails:

task test2
task: [child:work] echo "hello from child!"
hello from child!
task: [work] echo "hello from parent!"
hello from parent!
task: Failed to run task "test2": task: Task "child::work" does not exist

It seems that the templating has an effect on calling parent tasks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions