Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

potential bug: Variables in included files override ones in parent file #1800

Closed
pbitty opened this issue Sep 9, 2024 · 1 comment
Closed

Comments

@pbitty
Copy link
Contributor

pbitty commented Sep 9, 2024

When I include a Taskfile that has env and vars that overlap the parent taskfile, the parent file's variables get overwritten at parent tasks' scope.

I am running task with the following files:

Taskfile.yml

version: '3'

includes:
  child: ./Taskfile.child.yml

env:
  ENV_VAR: root-file

vars:
  VAR: root-file

tasks:
  default: |
    echo ENV_VAR is $ENV_VAR
    echo VAR is {{ .VAR }}

Taskfile.child.yml

version: '3'

env:
  ENV_VAR: child-file

vars:
  VAR: child-file

# No tasks needed for this example.

Expected output:

ENV_VAR is root-file
VAR is root-file

Actual output:

ENV_VAR is child-file
VAR is child-file

I believe the code responsible is here:

t1.Vars.Merge(t2.Vars, include)
t1.Env.Merge(t2.Env, include)
, where merge the included file's variables into the parent.

Is this intentional behaviour? I would expect that the parent could provide defaults for the child, or override via include.*.vars, but it is surprising to have the child influence values on the parent.

If this is indeed a bug, I'd be happy to contribute a fix.

  • Task version: HEAD@114d5e1
  • Operating system: MacOS 14.4.1
  • Experiments enabled: None
@task-bot task-bot added the state: needs triage Waiting to be triaged by a maintainer. label Sep 9, 2024
@vmaerten
Copy link
Member

Hello!

Variables are not scoped and we can't change it right now because it would be a breaking changes. We had a discussion about it here

TLDR: users should avoid has much as possible to use conflicting variable names for now because they are not scoped

@task-bot task-bot removed the state: needs triage Waiting to be triaged by a maintainer. label Sep 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants