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

fix: integer fields are displayed as floats when using describe with o=yaml #638

Closed
phm07 opened this issue Dec 14, 2023 · 1 comment · Fixed by #650, #651 or #652
Closed

fix: integer fields are displayed as floats when using describe with o=yaml #638

phm07 opened this issue Dec 14, 2023 · 1 comment · Fixed by #650, #651 or #652
Assignees
Labels

Comments

@phm07
Copy link
Contributor

phm07 commented Dec 14, 2023

When outputting resources in YAML format using describe, some integer fields (like IDs) are interpreted as floating point numbers and are thus unusable. Example output of $ hcloud image describe fedora-39 -o=yaml:

architecture: x86
bound_to: null
created: 2023-11-09T06:19:32+00:00
created_from: null
deleted: null
deprecated: null
description: Fedora 39
disk_size: 5.0
id: 1.35075974e+08 # interpreted as floating point
image_size: null
labels: {}
name: fedora-39
os_flavor: fedora
os_version: "39"
protection:
  delete: false
rapid_deploy: true
status: available
type: system

This is because when running describe, the API response is decoded into a map[string]any. The Go json library defaults to float64 when converting JSON number literals into an any, so in the encoding back to YAML these integer fields are interpreted as floats.

@phm07 phm07 added the bug label Dec 14, 2023
@phm07 phm07 self-assigned this Dec 14, 2023
@phm07 phm07 changed the title Integer fields are displayed as floats in YAML output fix: integer fields are displayed as floats when using describe with o=yaml Dec 19, 2023
@phm07 phm07 reopened this Dec 19, 2023
@phm07
Copy link
Contributor Author

phm07 commented Dec 19, 2023

The same is true for metrics and create commands.

phm07 added a commit that referenced this issue Dec 20, 2023
…yaml (#651)

Continuation #650, closes #638

When outputting a resource after creation, it is first converted into a
schema struct. This fixes bugs like #638 and also makes all schema
outputs (describe, list, create) consistent.

---------

Co-authored-by: jo <ljonas@riseup.net>
jooola pushed a commit that referenced this issue Dec 21, 2023
🤖 I have created a release *beep* *boop*
---


##
[1.41.1](v1.41.0...v1.41.1)
(2023-12-21)


### Bug Fixes

* allow multiple --type flags for metrics commands
([#649](#649))
([69346f7](69346f7)),
closes [#642](#642)
* integer fields are displayed as floats when using create with o=yaml
([#651](#651))
([2d42fcd](2d42fcd))
* integer fields are displayed as floats when using describe with
-o=yaml ([#650](#650))
([ee4c51e](ee4c51e)),
closes [#638](#638)
* wording when metrics are not yet available
([#639](#639))
([9298c46](9298c46))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment