concourse icon indicating copy to clipboard operation
concourse copied to clipboard

Fly cannot parse float64 from vars file

Open stuart-c-moore opened this issue 7 years ago • 4 comments

Bug Report

Fly 5.5 cannot parse a line in a vars file that was parsed successfully in 5.4.1

Steps to Reproduce

% head -4 ci/vars/pm-concourse-master.yml
# Destroy resources automatically. Pay close attention to this one!
terraform_destroy: false
terraform_destroy_disable_manual_trigger: true
terraform_destroy_sleep_seconds: 7200

% fly vp -c ci/pipeline.yml -l ci/vars/common.yml -l ci/vars/pm-concourse-master.yml
error: cannot interpolate non-primitive value (float64) from var: terraform_destroy_sleep_seconds

Expected Results

The file is parsed successfully. This is the case in 5.4.1

Actual Results

The following error is shown:

error: cannot interpolate non-primitive value (float64) from var: terraform_destroy_sleep_seconds

Additional Context

I have noticed that values of type float64 are not permitted:

https://github.com/concourse/concourse/blob/be412879cbf5a3c52a583c7ba194a7976d21e1a1/vars/template.go#L106

stuart-c-moore avatar Sep 10 '19 12:09 stuart-c-moore

I've found a reliable way to recreate the problem:

Given a vars.yml file with the following contents:

sleep: 7200

This works:

resource_types:
- name: slack-notification
  type: docker-image
  source:
    repository: cfcommunity/slack-notification-resource

resources:
- name: slack-warning
  type: slack-notification

jobs:
- name: terraform-destroy
  serial: true
  serial_groups: [terraform]
  plan:
  - put: slack-warning
    params:
      text: "((sleep))"
  - task: terraform destroy
    file: concourse/ci/tasks/terraform-destroy.yml
    params:
      TERRAFORM_DESTROY_SLEEP_SECONDS: ((sleep))
% fly vp -c pipeline.yml -l vars.yml
looks good

This errors:

resource_types:
- name: slack-notification
  type: docker-image
  source:
    repository: cfcommunity/slack-notification-resource

resources:
- name: slack-warning
  type: slack-notification

jobs:
- name: terraform-destroy
  serial: true
  serial_groups: [terraform]
  plan:
  - put: slack-warning
    params:
      text: " ((sleep))"
  - task: terraform destroy
    file: concourse/ci/tasks/terraform-destroy.yml
    params:
      TERRAFORM_DESTROY_SLEEP_SECONDS: ((sleep))
% fly vp -c pipeline.yml -l vars.yml
error: cannot interpolate non-primitive value (float64) from var: sleep

Note the additional space I entered before ((sleep)) on the text: line.

stuart-c-moore avatar Sep 10 '19 16:09 stuart-c-moore

Here's what's happening under the hood: Concourse is interpreting "((sleep))" the same as ((sleep)) - because before vars are processed, they're all string values. If there is no other content on either side of a var, Concourse just slips the value in there verbatim. If there is, tries to interpolate the var's value into the string. This is to support foo-((bar)).

Normally all is well and good, however it doesn't even try to interpolate floating point values because the exact notation that was used ends up being lost, and the notation may be important if the user wants the value concatenated into a string. For example, if the user entered 10.4e5 we don't want to end up with foo-104000.0.

Unfortunately all integer values are technically floating point because we convert the YAML to JSON and then use JSON unmarshaling, and all numeric values in JSON are floating point. This is a change I made in #3505, so that's why it broke in v5.5.

I'm not sure what we can really do about this. :thinking: This kind of issue has come up previously in #1407. My suggestion right now is to just be explicit about values which you expect to use as a string, and quote them.

vito avatar Sep 10 '19 18:09 vito

Declaring as a string won't work? sleep:"7200" In my case i had same issue checking out git branches and it worked.

reiser avatar Oct 26 '19 20:10 reiser

Beep boop! This issue has been idle for long enough that it's time to check in and see if it's still important.

If it is, what is blocking it? Would anyone be interested in submitting a PR or continuing the discussion to help move things forward?

If no activity is observed within the next week, this issue will be ~~exterminated~~ closed, in accordance with our stale issue process.

stale[bot] avatar Dec 25 '19 20:12 stale[bot]