Decimal fields conveyed as strings in the REST API
See original GitHub issueNetBox version
v2.11.2
Python version
3.9
Steps to Reproduce
The HTTP GET response returns “vcpu” argument as string, but it should be a float, as requested on Issue #5975.
Steps to reproduce:
- Make HTTP GET request to /api/virtualization/virtual-machines/{id}/
HTTP GET Request
URI: https://demo.netbox.dev/api/virtualization/virtual-machines/543/
Headers: Authorization: Token 977e9fb09fbfb2aa67ae06f90655b52edcee01e5 Host: demo.netbox.dev User-Agent: PostmanRuntime/7.28.0 Accept: / Accept-Encoding: gzip, deflate, br Connection: keep-alive Content-Type: application/json
Expected Behavior
HTTP GET Response
{
"id": 543,
"url": "https://demo.netbox.dev/api/virtualization/virtual-machines/543/",
"display": "vcpu is string, not float",
"name": "vcpu is string, not float",
"status": {
"value": "active",
"label": "Active"
},
"site": null,
"cluster": {
"id": 9,
"url": "https://demo.netbox.dev/api/virtualization/clusters/9/",
"display": "DO-AMS3",
"name": "DO-AMS3"
},
"role": null,
"tenant": null,
"platform": null,
"primary_ip": null,
"primary_ip4": null,
"primary_ip6": null,
"vcpus": 10.00,
"memory": 8196,
"disk": 50,
"comments": "",
"local_context_data": null,
"tags": [],
"custom_fields": {},
"config_context": {},
"created": "2021-05-04",
"last_updated": "2021-05-04T02:19:09.726988Z"
}
Observed Behavior
HTTP GET Response
{
"id": 543,
"url": "https://demo.netbox.dev/api/virtualization/virtual-machines/543/",
"display": "vcpu is string, not float",
"name": "vcpu is string, not float",
"status": {
"value": "active",
"label": "Active"
},
"site": null,
"cluster": {
"id": 9,
"url": "https://demo.netbox.dev/api/virtualization/clusters/9/",
"display": "DO-AMS3",
"name": "DO-AMS3"
},
"role": null,
"tenant": null,
"platform": null,
"primary_ip": null,
"primary_ip4": null,
"primary_ip6": null,
"vcpus": "10.00",
"memory": 8196,
"disk": 50,
"comments": "",
"local_context_data": null,
"tags": [],
"custom_fields": {},
"config_context": {},
"created": "2021-05-04",
"last_updated": "2021-05-04T02:19:09.726988Z"
}
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
Why would you use a string in JSON to represent a decimal ...
The main reason to transfer numeric values in JSON as strings is to eliminate any loss of precision or ambiguity in transfer.
Read more >json parse error converting string to decimal in rest api
Hi frnds, i have a class where json parameters come in string format among them two values come in decimal format i was...
Read more >Representing price in response and request - Meta - JSON API
Strings I think are easier for handling, would be converted to decimal inside handler. But then there is missing validation -> price is...
Read more >Zoned and Packed Decimal Fields as IDMS Keys - TechDocs
Zoned decimal fields use one byte of storage to represent each single digit within a value. The high-order nibble of the last byte...
Read more >REST API Fields - Cybersource Technical Documentation Portal
Data Type: String ... REST API Field: acquirerInformation.country ... 2.x messages to be communicated between all components (in minutes).
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m not sure it’s fair to classify this as a bug, since it is technically intended behavior, though I do think we’re okay to change it. Let’s tag this for v2.12.
Although your opinion makes sense and I had to do exactly what you said, this specific behavior in Netbox is very different from the rest of the system, so would be great to make things working as expected, as the system is so consistent.