BigAuto integer ID fields should be returned from the API as a string #5603

Closed
opened 2025-12-29 19:30:04 +01:00 by adam · 3 comments
Owner

Originally created by @TheEnbyperor on GitHub (Nov 3, 2021).

NetBox version

v3.0.8

Python version

3.9

Steps to Reproduce

When dealing with large row IDs such as those generated by cockroachDB, the JS floating point implementation can alter IDs returned from the API when parsing JSON. This results in nonexistent rows being queried.

As can be seen below the ID in JSON and the ID in JS do not match up.

let data = JSON.parse('{"count":1,"next":null,"previous":null,"results":[{"id":707372639259361282,"url":"http://nb.as207960.net/api/ipam/rirs/707372639259361282/","display":"RIPE","name":"RIPE","slug":"ripe","aggregate_count":1}]}');
// data.results[0].id
707372639259361300

This results in selection boxes in the web interface being non functional.

Expected Behavior

It should be possible to use the web interface error free and make selections from selection boxes.

Observed Behavior

When using the web interface many errors come up complaining about selections not being valid, this is due to JS mangling the IDs as described above.

Originally created by @TheEnbyperor on GitHub (Nov 3, 2021). ### NetBox version v3.0.8 ### Python version 3.9 ### Steps to Reproduce When dealing with large row IDs such as those generated by cockroachDB, the JS floating point implementation can alter IDs returned from the API when parsing JSON. This results in nonexistent rows being queried. As can be seen below the ID in JSON and the ID in JS do not match up. ```js let data = JSON.parse('{"count":1,"next":null,"previous":null,"results":[{"id":707372639259361282,"url":"http://nb.as207960.net/api/ipam/rirs/707372639259361282/","display":"RIPE","name":"RIPE","slug":"ripe","aggregate_count":1}]}'); // data.results[0].id 707372639259361300 ``` This results in selection boxes in the web interface being non functional. ### Expected Behavior It should be possible to use the web interface error free and make selections from selection boxes. ### Observed Behavior When using the web interface many errors come up complaining about selections not being valid, this is due to JS mangling the IDs as described above.
adam closed this issue 2025-12-29 19:30:04 +01:00
Author
Owner

@kkthxbye-code commented on GitHub (Nov 3, 2021):

While you are right in that you can only load numbers up to 9007199254740991 in a javascript number type, how are you getting autoincremented id's that high in the first place? The autoincremented id of objects in netbox are generally not exposed when creating objects at all afaik.

@kkthxbye-code commented on GitHub (Nov 3, 2021): While you are right in that you can only load numbers up to 9007199254740991 in a javascript number type, how are you getting autoincremented id's that high in the first place? The autoincremented id of objects in netbox are generally not exposed when creating objects at all afaik.
Author
Owner

@TheEnbyperor commented on GitHub (Nov 4, 2021):

The database row ID is exposed in the API in places such as https://nb.as207960.net/api/ipam/rirs/. IDs so high are generated when running the database server in a distributed cluster, so each row ID is a snowflake rather than a purely auto incrementing ID.

@TheEnbyperor commented on GitHub (Nov 4, 2021): The database row ID is exposed in the API in places such as `https://nb.as207960.net/api/ipam/rirs/`. IDs so high are generated when running the database server in a distributed cluster, so each row ID is a snowflake rather than a purely auto incrementing ID.
Author
Owner

@jeremystretch commented on GitHub (Nov 5, 2021):

When dealing with large row IDs such as those generated by cockroachDB

NetBox doesn't officially support deployment using CockroachDB, so I'm afraid this can't be classified as a bug. While there may be some viable workaround, recasting all integer fields to strings (as suggested in your earlier PR) would not be tenable. Perhaps there's a mechanism to configure the maximum allowed primary key value within CockroachDB? Or, you might consider writing a shim layer for the API to handle the conversion.

Either way, I think ~9 quadrillion is a reasonable limit for the maximum PK value for NetBox objects.

@jeremystretch commented on GitHub (Nov 5, 2021): > When dealing with large row IDs such as those generated by cockroachDB NetBox doesn't officially support deployment using CockroachDB, so I'm afraid this can't be classified as a bug. While there may be some viable workaround, recasting all integer fields to strings (as suggested in your earlier PR) would not be tenable. Perhaps there's a mechanism to configure the maximum allowed primary key value within CockroachDB? Or, you might consider writing a shim layer for the API to handle the conversion. Either way, I think ~9 quadrillion is a reasonable limit for the maximum PK value for NetBox objects.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#5603