Cannot edit values in decimal fields when the difference is not divisible by 0.0001 #8338

Closed
opened 2025-12-29 20:35:31 +01:00 by adam · 12 comments
Owner

Originally created by @alryaz on GitHub (Jul 14, 2023).

NetBox version

v3.5.6

Python version

3.10

Steps to Reproduce

  1. Create a custom decimal field
  2. Populate this field externally (using, for example, pynetbox API) using a value that is not divisible by 0.0001 without remainder (ex. 199.99999)
  3. Open editing page of the object for which field population occurred
  4. Enter a new value that differs from existing one, but is divisible by 0.0001 (ex. 200)
  5. Submit editing form
  6. An error message surrounding the field arises stating that the new value is invalid, and that the closest valid candidates are within ±0.0001 of the previous field (ex. 199.99989 & 200.00009)

Expected Behavior

Value saved to database on submission, no error arises

Observed Behavior

Frontend prevents from submitting custom decimal field values whose abs(NewValue - CurrentValue) mod 0.0001 > 0

Example of such value: 199.447543808 changed to 200:

  • New value remainder: 199.447543808 mod 0.0001 = 0.00004380799
  • Changes remainder: abs(200-199.447543808) mod 0.0001 = 0.00005619199

Note: This is a frontend issue, not a backend one. The step attribute (in <input ... step="0.0001" ...> is what causes it)

(Possible) Feature request

Add ability to set custom resolution to decimal point fields

Originally created by @alryaz on GitHub (Jul 14, 2023). ### NetBox version v3.5.6 ### Python version 3.10 ### Steps to Reproduce 1. Create a custom decimal field 2. Populate this field externally (using, for example, _pynetbox_ API) using a value that is not divisible by 0.0001 without remainder (ex. 199.99999) 3. Open editing page of the object for which field population occurred 4. Enter a new value that differs from existing one, but is divisible by 0.0001 (ex. 200) 5. Submit editing form 6. An error message surrounding the field arises stating that the new value is invalid, and that the closest valid candidates are within ±0.0001 of the previous field (ex. 199.99989 & 200.00009) ### Expected Behavior Value saved to database on submission, no error arises ### Observed Behavior Frontend prevents from submitting custom decimal field values whose `abs(NewValue - CurrentValue) mod 0.0001 > 0` Example of such value: 199.447543808 changed to 200: - New value remainder: `199.447543808 mod 0.0001 = 0.00004380799` - Changes remainder: `abs(200-199.447543808) mod 0.0001 = 0.00005619199` _Note:_ This is a frontend issue, not a backend one. The _step_ attribute (in `<input ... step="0.0001" ...>` is what causes it) ### (Possible) Feature request Add ability to set custom resolution to decimal point fields
adam added the type: bugstatus: needs ownerpending closureseverity: low labels 2025-12-29 20:35:31 +01:00
adam closed this issue 2025-12-29 20:35:31 +01:00
Author
Owner

@jsenecal commented on GitHub (Jul 14, 2023):

Thank you for opening a bug report. Unfortunately, the information you have provided is not sufficient for someone else to attempt to reproduce the reported behavior. Remember, each bug report must include detailed steps that someone else can follow on a clean, empty NetBox installation to reproduce the exact problem you're experiencing. These instructions should include the creation of any involved objects, any configuration changes, and complete accounting of the actions being taken. Also be sure that your report does not reference data on the public NetBox demo, as that is subject to change at any time by an outside party and cannot be relied upon for bug reports.

Could you please provide the steps to replicate your issue with an empty installation ?

@jsenecal commented on GitHub (Jul 14, 2023): Thank you for opening a bug report. Unfortunately, the information you have provided is not sufficient for someone else to attempt to reproduce the reported behavior. Remember, each bug report must include detailed steps that someone else can follow on a clean, empty NetBox installation to reproduce the exact problem you're experiencing. These instructions should include the creation of any involved objects, any configuration changes, and complete accounting of the actions being taken. Also be sure that your report does not reference data on the public NetBox demo, as that is subject to change at any time by an outside party and cannot be relied upon for bug reports. Could you please provide the steps to replicate your issue with an empty installation ?
Author
Owner

@jeremystretch commented on GitHub (Jul 25, 2023):

This issue is being closed as no further information has been provided. If you would like to revisit this topic, please first modify your original post to include all the requested detail, and then ask that the issue be reopened.

@jeremystretch commented on GitHub (Jul 25, 2023): This issue is being closed as no further information has been provided. If you would like to revisit this topic, please first modify your original post to include all the requested detail, and then ask that the issue be reopened.
Author
Owner

@kkthxbye-code commented on GitHub (Jul 25, 2023):

I mean he did edit the post afterwards, he just didn't make a new post saying he did.

@kkthxbye-code commented on GitHub (Jul 25, 2023): I mean he did edit the post afterwards, he just didn't make a new post saying he did.
Author
Owner

@jsenecal commented on GitHub (Jul 28, 2023):

We were able to reproduce this bug - I reopened the issue

@jsenecal commented on GitHub (Jul 28, 2023): We were able to reproduce this bug - I reopened the issue
Author
Owner

@jsenecal commented on GitHub (Jul 28, 2023):

@alryaz would you happen to know an easy way to fix this and would you like this issue assigned to you ?

@jsenecal commented on GitHub (Jul 28, 2023): @alryaz would you happen to know an easy way to fix this and would you like this issue assigned to you ?
Author
Owner

@jsenecal commented on GitHub (Jul 28, 2023):

A potential solution would be to round the value to 4 decimals with javascript

element.addEventListener('change', function() {
    var value = +this.value;
    if (value === value) this.value = value.toFixed(4);
}, false)

Number.prototype.toFixed() Reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed

Or do it / raise a validation error while validating the model and avoid the issue altogether.

@jsenecal commented on GitHub (Jul 28, 2023): A potential solution would be to round the value to 4 decimals with javascript ```javascript element.addEventListener('change', function() { var value = +this.value; if (value === value) this.value = value.toFixed(4); }, false) ``` `Number.prototype.toFixed()` Reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed Or do it / raise a validation error while validating the model and avoid the issue altogether.
Author
Owner

@Kage1 commented on GitHub (Sep 1, 2023):

As a follow up, it would be helpful if decimals were allowed at least 6 digits. This would allow storage of high precision numbers like custom latitude/latitude.

@Kage1 commented on GitHub (Sep 1, 2023): As a follow up, it would be helpful if decimals were allowed at least 6 digits. This would allow storage of high precision numbers like custom latitude/latitude.
Author
Owner

@pv2b commented on GitHub (Sep 18, 2023):

I have to ask, why does NetBox even care about how precise numbers stored in the database are? What's the problem it's trying to solve?

Unless there's any specific reason NetBox does it this way, It seems the correct approach is to allow storing numbers of arbitrary precision (well, up to the precision of the underlying datatype) and then just doing any rounding on the output side.

@pv2b commented on GitHub (Sep 18, 2023): I have to ask, why does NetBox even care about how precise numbers stored in the database are? What's the problem it's trying to solve? Unless there's any specific reason NetBox does it this way, It seems the correct approach is to allow storing numbers of arbitrary precision (well, up to the precision of the underlying datatype) and then just doing any rounding on the output side.
Author
Owner

@github-actions[bot] commented on GitHub (Dec 18, 2023):

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Do not attempt to circumvent this process by "bumping" the issue; doing so will result in its immediate closure and you may be barred from participating in any future discussions. Please see our contributing guide.

@github-actions[bot] commented on GitHub (Dec 18, 2023): This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. **Do not** attempt to circumvent this process by "bumping" the issue; doing so will result in its immediate closure and you may be barred from participating in any future discussions. Please see our [contributing guide](https://github.com/netbox-community/netbox/blob/develop/CONTRIBUTING.md).
Author
Owner

@jeremystretch commented on GitHub (Dec 26, 2023):

Populate this field externally (using, for example, pynetbox API) using a value that is not divisible by 0.0001 without remainder (ex. 199.99999)

This is not supported: The declared precision of a custom decimal field is four decimal places. The bug in effect is that the specified value is not being rounded to the supported level of precision.

Note: This is a frontend issue, not a backend one. The step attribute (in <input ... step="0.0001" ...> is what causes it)

This is because Django reasonably renders DecimalField with the step attribute set to the declared precision.

@jeremystretch commented on GitHub (Dec 26, 2023): > Populate this field externally (using, for example, pynetbox API) using a value that is not divisible by 0.0001 without remainder (ex. 199.99999) This is not supported: The declared precision of a custom decimal field is four decimal places. The bug in effect is that the specified value is not being rounded to the supported level of precision. > Note: This is a frontend issue, not a backend one. The step attribute (in `<input ... step="0.0001" ...>` is what causes it) This is because Django reasonably renders DecimalField with the `step` attribute set to the declared precision.
Author
Owner

@github-actions[bot] commented on GitHub (Mar 26, 2024):

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Do not attempt to circumvent this process by "bumping" the issue; doing so will result in its immediate closure and you may be barred from participating in any future discussions. Please see our contributing guide.

@github-actions[bot] commented on GitHub (Mar 26, 2024): This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. **Do not** attempt to circumvent this process by "bumping" the issue; doing so will result in its immediate closure and you may be barred from participating in any future discussions. Please see our [contributing guide](https://github.com/netbox-community/netbox/blob/develop/CONTRIBUTING.md).
Author
Owner

@arthanson commented on GitHub (Apr 19, 2024):

Closing as by design, See Jeremy's comments above.

@arthanson commented on GitHub (Apr 19, 2024): Closing as by design, See Jeremy's comments above.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#8338