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

Error 'query apply called but it should never have changes' #632

Open
dmlemos opened this issue Jul 10, 2017 · 0 comments
Open

Error 'query apply called but it should never have changes' #632

dmlemos opened this issue Jul 10, 2017 · 0 comments
Assignees
Labels

Comments

@dmlemos
Copy link

dmlemos commented Jul 10, 2017

Given

param "node_version" {
  default = "1.0"
}

Case 1

task.query "get-version" {
  query = "node version 2>/dev/null | grep '{{param `node_version`}}'"

  group = "install"
}

switch "test-version" {
  case "eq `` `{{lookup `task.query.get-version.status.stdout`}}`" "version-not-found" {
    task "download" {
      check = "exit 1"

      apply = "curl ..."

      group = "install"
    }

    task "retire" {
      check = "exit 1"

      apply = "node retire"

      group   = "install"
    }
  }
}

Case 2

task.query "get-version" {
  query = "node version 2>/dev/null | grep -q '{{param `node_version`}}'"

  group = "install"
}

switch "test-version" {
  case "eq `1` `{{lookup `task.query.get-version.status.exitstatus`}}`" "version-not-found" {
    task "download" {
      check = "exit 1"

      apply = "curl ..."

      group = "install"
    }

    task "retire" {
      check = "exit 1"

      apply = "node retire"

      group   = "install"
    }
  }
}

The exit 1 on the tasks seems to be needed, as I want it to execute the whole block when the version mismatch.

Result

check

Summary: 0 errors, 3 changes

apply

root/module.main/task.query.get-version:
 Error: root/module.main/task.query.get-version still has changes after apply: query apply called but it should never have changes
 Messages:
  check (returned: 1)

 Has Changes: yes
 Changes: No changes

Errors:
 * root/module.main/task.query.get-version: root/module.main/task.query.get-version still has changes after apply: query apply called but it should never have changes

Failed due to failing dependency:
* root/module.main/macro.switch.get-version/macro.case.version-not-found/task.retire: error in dependency "root/module.main/task.query.check-version"
 * root/module.main: error in dependency "root/module.main/macro.switch.get-version"
 * root/module.main/macro.switch.get-version/macro.case.version-not-found: error in dependency "root/module.main/task.query.get-version"
 * root/module.main/macro.switch.get-version/macro.case.version-not-found/task.download: error in dependency "root/module.main/task.query.get-version"
 * root/module.main/macro.switch.get-version: error in dependency "root/module.main/macro.switch.test-version/macro.case.version-not-found"

Summary: 1 errors, 0 changes, 5 dependency errors

UPDATE

Found a workaround.

task.query "get-version" {
  query = "node version 2>/dev/null | grep '{{param `node_version`}}'; true"

  group = "install"
}

switch "test-version" {
  case "eq `` `{{lookup `task.query.get-version.status.stdout`}}`" "version-not-found" {
    task "download" {
      check = "exit 1"

      apply = "curl ..."

      group = "install"
    }

    task "retire" {
      check = "exit 1"

      apply = "node retire"

      group   = "install"
    }
  }
}

It works if I return true on the task.query, although still allows me to check for the value 😄

Only stdout can be used as the exitstatus will always break the apply.
Unfortunately evaluate of eq is also broken. Can only validate if value is empty. If I try to check the version there it fails.

Seems like task.query is evaluating the error code again after the tasks have been applied. That's a surprise.

@rebeccaskinner rebeccaskinner self-assigned this Jul 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants