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

Long number string variables are now converted to scientific notation, breaking existing tasks that expect the number as is #1658

Closed
manzamor-cs opened this issue May 14, 2024 · 4 comments
Labels
type: question Further information is requested.

Comments

@manzamor-cs
Copy link

Existing commands that utilize a long number variable as a string are now broken by conversion to scientific notation.

Given this task:

  long-number:
    desc: Print a long number variable
    vars:
      LONG_NUMBER: 123456789012345678901234567890
    cmds:
      - echo "{{.LONG_NUMBER}}"

Using task version 3.36.0:

❯ task long-number      
task: [long-number] echo "123456789012345678901234567890"
123456789012345678901234567890

Using task version 3.37.2:

❯ task long-number 
task: [long-number] echo "1.2345678901234568e+29"
1.2345678901234568e+29

The issue can fixed by just quoting the variable that is meant to be interpreted as a string, but this does break previously existing tasks that utilize unquoted long numbers.

  • Task version: 3.37.2
  • Operating system: Mac OS/Linux
  • Experiments enabled: Nope
@task-bot task-bot added the state: needs triage Waiting to be triaged by a maintainer. label May 14, 2024
@pd93
Copy link
Member

pd93 commented May 14, 2024

This is behaving as intended. Since Task now supports any scalar variable type, if you give it a number, it will be interpreted as one (rather than the previous behaviour which automatically converted it to a string). Since the number you used far exceeds the maximum signed and unsigned 64 bit integer size, it is converted to a float approximation instead and when printed it will be displayed using scientific notation.

If you want your variable to be a string then you should always wrap it with quotes and it will be interpreted as expected:

  long-number:
    desc: Print a long number variable
    vars:
      LONG_NUMBER: "123456789012345678901234567890"
    cmds:
      - echo "{{.LONG_NUMBER}}"

@pd93 pd93 closed this as completed May 14, 2024
@pd93 pd93 added the type: question Further information is requested. label May 14, 2024
@task-bot task-bot removed the state: needs triage Waiting to be triaged by a maintainer. label May 14, 2024
@manzamor-cs
Copy link
Author

manzamor-cs commented May 14, 2024

I figured this might be the intended behavior and included the bit about the quotes after the example I provided. For future reference, should I assume minor version bumps could introduce breaking changes?

@pd93
Copy link
Member

pd93 commented May 14, 2024

We don't (intentionally) make breaking changes in minor/patch versions. We follow SemVer rules for our CLI binary (Though it's worth remembering that the Golang package API does not share this compatibility guarantee). This is one of the reasons why we have experiment flags (for testing breaking changes to be made in future major releases).

I understand that this release made some Taskfiles behave differently. However, I would argue that this is still not considered to be a breaking change since it only changes the behaviour of incorrectly formatted YAML files. If anything, I would consider the previous behaviour to be buggy and we should have been erroring if we detected non-string variables.

The fact that in prior versions, you could define a YAML boolean and then not use {{if .BOOL_VAR}} when templating was not intuitive at all. Likewise, defining a YAML number without quotes implies that you should be able to do {{index (list 1 2 3) .NUM_VAR}}. However, this would have errored with cannot index slice/array with type string. In 3.37.0+ both these scenarios work as expected.

Sidenote: One of my least favourite things about YAML is that it lets you define strings without using quotes. It leads to a lot of problems/misunderstandings. Especially given that y, n, yes, no, on, off, true and false are all parsed as bools depending on the parser and YAML version you're using. It's just messy and should be avoided at all costs. There is plenty of discussion on this topic on StackOverflow.

One thing is for sure though. If you want a string containing numeric-only characters - you need to quote it.

@manzamor-cs
Copy link
Author

I understand what you mean about the previous behavior being considered a bug. I guess whether this is considered a "breaking change" is open to interpretation, but I can definitely see your point. Thanks for the explanation! 👍🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question Further information is requested.
Projects
None yet
Development

No branches or pull requests

3 participants