[PR #18039] [MERGED] Fixes: #18038 - Ensure DeviceType._abs_weight is stored as an integer #15258

Closed
opened 2025-12-30 00:20:55 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbox-community/netbox/pull/18039
Author: @bctiemann
Created: 11/18/2024
Status: Merged
Merged: 11/20/2024
Merged by: @jeremystretch

Base: developHead: 162-store-_abs_weight-as-int


📝 Commits (2)

  • 634634d Coerce _abs_weight to int to prevent disagreement with PositiveBigIntegerField deserialization
  • cb94928 Perform coercion in to_grams

📊 Changes

1 file changed (+6 additions, -6 deletions)

View changed files

📝 netbox/utilities/conversion.py (+6 -6)

📄 Description

Fixes: #18038

WeightMixin provides an _abs_weight field which stores the normalized weight in grams. It is a PositiveBigIntegerField, yet the value stored in it is the unvalidated output of to_grams, which may be a float. This does not normally cause issues in the app, but in the case of netbox-branching, the field validation fails when the field value is synced from one branch to another because it expects an integer but receives a float.

This fix adds type annotation and consistent return values to to_grams.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/netbox-community/netbox/pull/18039 **Author:** [@bctiemann](https://github.com/bctiemann) **Created:** 11/18/2024 **Status:** ✅ Merged **Merged:** 11/20/2024 **Merged by:** [@jeremystretch](https://github.com/jeremystretch) **Base:** `develop` ← **Head:** `162-store-_abs_weight-as-int` --- ### 📝 Commits (2) - [`634634d`](https://github.com/netbox-community/netbox/commit/634634d65b08a85d00c2e9e126e886b2f97b8852) Coerce _abs_weight to int to prevent disagreement with PositiveBigIntegerField deserialization - [`cb94928`](https://github.com/netbox-community/netbox/commit/cb949283eae381736fb8942db90772a980ae87cb) Perform coercion in to_grams ### 📊 Changes **1 file changed** (+6 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `netbox/utilities/conversion.py` (+6 -6) </details> ### 📄 Description ### Fixes: #18038 `WeightMixin` provides an `_abs_weight` field which stores the normalized weight in grams. It is a `PositiveBigIntegerField`, yet the value stored in it is the unvalidated output of `to_grams`, which may be a float. This does not normally cause issues in the app, but in the case of netbox-branching, the field validation fails when the field value is synced from one branch to another because it expects an integer but receives a float. This fix adds type annotation and consistent return values to `to_grams`. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2025-12-30 00:20:55 +01:00
adam closed this issue 2025-12-30 00:20:55 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#15258