-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Decimal fields conveyed as strings in the REST API #6338
Comments
I'm not sure why these values are getting quoted. As far as I can tell the serializer field is defined correctly. Could be an issue with DRF itself.
|
Ok, yes, this seems to be intentional behavior by DRF: See the While I recognize that precision isn't likely a concern for this specific use case, I'm hesitant to deviate from the standard implementation. I can see this becoming quite muddy for values such as cable lengths. |
This also affects
|
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. |
In general, I have an opinion of never expect specific data types in responses. Given all APIs out there one thing that I have discovered is that you have to catch and format data anyway before processing. To be honest, life would be easier if everything was strings, and the processing of responses handle convversions. But thats me, always encapsulating stuff in str(), int(), float() and so on... |
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. |
NetBox 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:
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
Observed Behavior
HTTP GET Response
The text was updated successfully, but these errors were encountered: