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

Config: Avoid emitting integers in objects using exponent notation #7005

Merged
merged 2 commits into from
May 10, 2021

Conversation

justinvp
Copy link
Member

Config values that are objects are represented in memory as JSON strings. When a config map is being saved to a file, object values are first unmarshaled from JSON to interface{} and then the entire config map is marshaled to YAML (or JSON) and saved to disk. When an object value is unmarshaled from JSON, any numbers in the JSON string were being implicitly unmarshaled as float64, which resulted in some numbers in the nested objects being emitted in YAML using exponent notation (e.g. a number 12321123131 in an object value was being saved in the YAML as 1.2321123131e+10). To address this, when unmarshaling the JSON for an object value, first try to unmarshal any numbers as int64, falling back to float64.

Fixes #6787

Before

Running pulumi config set --path parent.nested 12321123131 resulted in Pulumi.<stack>.yaml having:

config:
  proj:parent:
    nested: 1.2321123131e+10

After

Running pulumi config set --path parent.nested 12321123131 resulted in Pulumi.<stack>.yaml having:

config:
  proj:parent:
    nested: 12321123131

Config values that are objects are represented in memory as JSON strings. When a config map is being saved to a file, object values are first unmarshaled from JSON to `interface{}` and then the entire config map is marshaled to YAML (or JSON) and saved to disk. When an object value is unmarshaled from JSON, any numbers in the JSON string were being implicitly unmarshaled as `float64`, which resulted in some numbers in the nested objects being emitted in YAML using exponent notation (e.g. a number `12321123131` in an object value was being saved in the YAML as `1.2321123131e+10`). To address this, when unmarshaling the JSON for an object value, first try to unmarshal any numbers as `int64`, falling back to `float64`.
@justinvp justinvp requested a review from stack72 May 10, 2021 15:45
Copy link
Contributor

@stack72 stack72 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much for this! This is a great bug fix

@justinvp justinvp merged commit dad7f2c into master May 10, 2021
@pulumi-bot pulumi-bot deleted the justin/confignum branch May 10, 2021 17:00
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

Successfully merging this pull request may close these issues.

pulumi config set converts numbers into exponential notation when path based
2 participants