DeviceType._abs_weight being stored as float value though it is a PositiveBigIntegerField #18038
Labels
netbox
severity: medium
Results in substantial degraded or broken functionality for specfic workflows
status: accepted
This issue has been accepted for implementation
type: bug
A confirmed report of unexpected behavior in the application
Deployment Type
Self-hosted
Triage priority
I volunteer to perform this work (if approved)
NetBox Version
v4.1.6
Python Version
3.11
Steps to Reproduce
It is possible to store a non-integer value in
WeighMixin._abs_weight
fields (which arePositiveBigIntegerField
) prior to the object being persisted to the database. This potentially causes deserialization errors when populating a new object via a core serializer which uses the field'sto_python
method.Expected Behavior
The value of
DeviceType._abs_weight
should be the same (an integer value) both before and after persistence and refresh from the DB.Observed Behavior
As we see here, a
DeviceType
object populated with a non-integer weight will have that non-integer value assigned to_abs_weight
until the object is persisted to the database and refreshed. If, however, theDeviceType
object is populated with data and not refreshed from the DB before it is used in another operation (such as deserialization into anotherDeviceType
object), aDeserializationError
is raised from the field'sto_python
code which expects an integer but receives a float.The cause is this code:
The output of
to_grams
should be coerced to an int before being assigned toself._abs_weight
.Note: Moved from netboxlabs/netbox-branching#162
The text was updated successfully, but these errors were encountered: