Custom Field ValueError when gathering devices via API after changing the type of custom field #3703

Closed
opened 2025-12-29 18:30:41 +01:00 by adam · 6 comments
Owner

Originally created by @jvanderaa on GitHub (May 18, 2020).

Environment

  • Python version: python:3.8.2-buster
  • NetBox version: 2.8.1

Workaround is available, not sure if there would be a fix, or just some constraints to add.

Steps to Reproduce

  1. Disable any installed plugins by commenting out the PLUGINS setting in
    configuration.py.
  2. Create a custom field with type text
  3. Add data to the custom field ("True")
  4. Change the custom field type to bool
  5. Attempt to gather a device list with the API end point - {nb_url}/api/dcim/devices/?limit=0
  6. Then observe the 500 Internal Service error

Expected Behavior

I would look to have the fields either to be cleared out or if possible converted (more effort/work). Workaround of deleting and re-creating the custom field is appropriate.

Observed Behavior

pynetbox

pynetbox.core.query.RequestError: The request failed with code 500 Internal Server Error but more specific details were not returned in json. Check the NetBox Logs or investigate this exception's error attribute.

server logs

[18/May/2020 17:40:20] "GET /api/dcim/devices/?limit=0 HTTP/1.1" 500 23895
[18/May/2020 17:40:34] "GET / HTTP/1.1" 200 64062
Internal Server Error: /api/dcim/devices/
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
    response = get_response(request)
  File "/usr/local/lib/python3.7/site-packages/django/core/handlers/base.py", line 115, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/usr/local/lib/python3.7/site-packages/django/core/handlers/base.py", line 113, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/usr/local/lib/python3.7/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/rest_framework/viewsets.py", line 114, in view
    return self.dispatch(request, *args, **kwargs)
  File "/opt/netbox/netbox/utilities/api.py", line 330, in dispatch
    return super().dispatch(request, *args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/rest_framework/views.py", line 505, in dispatch
    response = self.handle_exception(exc)
  File "/usr/local/lib/python3.7/site-packages/rest_framework/views.py", line 465, in handle_exception
    self.raise_uncaught_exception(exc)
  File "/usr/local/lib/python3.7/site-packages/rest_framework/views.py", line 476, in raise_uncaught_exception
    raise exc
  File "/usr/local/lib/python3.7/site-packages/rest_framework/views.py", line 502, in dispatch
    response = handler(request, *args, **kwargs)
  File "/opt/netbox/netbox/utilities/api.py", line 348, in list
    return super().list(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/rest_framework/mixins.py", line 42, in list
    serializer = self.get_serializer(page, many=True)
  File "/opt/netbox/netbox/utilities/api.py", line 305, in get_serializer
    return super().get_serializer(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/rest_framework/generics.py", line 110, in get_serializer
    return serializer_class(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/rest_framework/serializers.py", line 122, in __new__
    return cls.many_init(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/rest_framework/serializers.py", line 143, in many_init
    child_serializer = cls(*args, **kwargs)
  File "/opt/netbox/netbox/extras/api/customfields.py", line 153, in __init__
    self._populate_custom_fields(obj, fields)
  File "/opt/netbox/netbox/extras/api/customfields.py", line 160, in _populate_custom_fields
    value = instance.cf.get(field.name)
  File "/opt/netbox/netbox/extras/models.py", line 201, in cf
    self.cache_custom_fields()
  File "/opt/netbox/netbox/extras/models.py", line 192, in cache_custom_fields
    field.name: value for field, value in self.get_custom_fields().items()
  File "/opt/netbox/netbox/extras/models.py", line 216, in get_custom_fields
    values_dict = {cfv.field_id: cfv.value for cfv in values}
  File "/opt/netbox/netbox/extras/models.py", line 216, in <dictcomp>
    values_dict = {cfv.field_id: cfv.value for cfv in values}
  File "/opt/netbox/netbox/extras/models.py", line 412, in value
    return self.field.deserialize_value(self.serialized_value)
  File "/opt/netbox/netbox/extras/models.py", line 305, in deserialize_value
    return bool(int(serialized_value))
ValueError: invalid literal for int() with base 10: 'True'
Originally created by @jvanderaa on GitHub (May 18, 2020). ### Environment * Python version: python:3.8.2-buster * NetBox version: 2.8.1 _Workaround_ is available, not sure if there would be a fix, or just some constraints to add. <!-- Describe in detail the exact steps that someone else can take to reproduce this bug using the current stable release of NetBox. Begin with the creation of any necessary database objects and call out every operation being performed explicitly. If reporting a bug in the REST API, be sure to reconstruct the raw HTTP request(s) being made: Don't rely on a client library such as pynetbox. --> ### Steps to Reproduce 1. Disable any installed plugins by commenting out the `PLUGINS` setting in `configuration.py`. 2. Create a custom field with type `text` 3. Add data to the custom field ("True") 4. Change the custom field type to `bool` 5. Attempt to gather a device list with the API end point - `{nb_url}/api/dcim/devices/?limit=0` 6. Then observe the 500 Internal Service error <!-- What did you expect to happen? --> ### Expected Behavior I would look to have the fields either to be cleared out or if possible converted (more effort/work). Workaround of deleting and re-creating the custom field is appropriate. <!-- What happened instead? --> ### Observed Behavior **pynetbox** ``` pynetbox.core.query.RequestError: The request failed with code 500 Internal Server Error but more specific details were not returned in json. Check the NetBox Logs or investigate this exception's error attribute. ``` **server logs** ``` [18/May/2020 17:40:20] "GET /api/dcim/devices/?limit=0 HTTP/1.1" 500 23895 [18/May/2020 17:40:34] "GET / HTTP/1.1" 200 64062 Internal Server Error: /api/dcim/devices/ Traceback (most recent call last): File "/usr/local/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner response = get_response(request) File "/usr/local/lib/python3.7/site-packages/django/core/handlers/base.py", line 115, in _get_response response = self.process_exception_by_middleware(e, request) File "/usr/local/lib/python3.7/site-packages/django/core/handlers/base.py", line 113, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/usr/local/lib/python3.7/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view return view_func(*args, **kwargs) File "/usr/local/lib/python3.7/site-packages/rest_framework/viewsets.py", line 114, in view return self.dispatch(request, *args, **kwargs) File "/opt/netbox/netbox/utilities/api.py", line 330, in dispatch return super().dispatch(request, *args, **kwargs) File "/usr/local/lib/python3.7/site-packages/rest_framework/views.py", line 505, in dispatch response = self.handle_exception(exc) File "/usr/local/lib/python3.7/site-packages/rest_framework/views.py", line 465, in handle_exception self.raise_uncaught_exception(exc) File "/usr/local/lib/python3.7/site-packages/rest_framework/views.py", line 476, in raise_uncaught_exception raise exc File "/usr/local/lib/python3.7/site-packages/rest_framework/views.py", line 502, in dispatch response = handler(request, *args, **kwargs) File "/opt/netbox/netbox/utilities/api.py", line 348, in list return super().list(*args, **kwargs) File "/usr/local/lib/python3.7/site-packages/rest_framework/mixins.py", line 42, in list serializer = self.get_serializer(page, many=True) File "/opt/netbox/netbox/utilities/api.py", line 305, in get_serializer return super().get_serializer(*args, **kwargs) File "/usr/local/lib/python3.7/site-packages/rest_framework/generics.py", line 110, in get_serializer return serializer_class(*args, **kwargs) File "/usr/local/lib/python3.7/site-packages/rest_framework/serializers.py", line 122, in __new__ return cls.many_init(*args, **kwargs) File "/usr/local/lib/python3.7/site-packages/rest_framework/serializers.py", line 143, in many_init child_serializer = cls(*args, **kwargs) File "/opt/netbox/netbox/extras/api/customfields.py", line 153, in __init__ self._populate_custom_fields(obj, fields) File "/opt/netbox/netbox/extras/api/customfields.py", line 160, in _populate_custom_fields value = instance.cf.get(field.name) File "/opt/netbox/netbox/extras/models.py", line 201, in cf self.cache_custom_fields() File "/opt/netbox/netbox/extras/models.py", line 192, in cache_custom_fields field.name: value for field, value in self.get_custom_fields().items() File "/opt/netbox/netbox/extras/models.py", line 216, in get_custom_fields values_dict = {cfv.field_id: cfv.value for cfv in values} File "/opt/netbox/netbox/extras/models.py", line 216, in <dictcomp> values_dict = {cfv.field_id: cfv.value for cfv in values} File "/opt/netbox/netbox/extras/models.py", line 412, in value return self.field.deserialize_value(self.serialized_value) File "/opt/netbox/netbox/extras/models.py", line 305, in deserialize_value return bool(int(serialized_value)) ValueError: invalid literal for int() with base 10: 'True' ```
adam added the pending closure label 2025-12-29 18:30:41 +01:00
adam closed this issue 2025-12-29 18:30:41 +01:00
Author
Owner

@jeremystretch commented on GitHub (May 20, 2020):

  1. Add some data (such as true/false)

Please specify exactly what data is being added. Keep in mind that someone else is relying on your instructions to replicate the reported bug.

@jeremystretch commented on GitHub (May 20, 2020): > 3. Add some data (such as true/false) Please specify exactly what data is being added. Keep in mind that someone else is relying on your instructions to replicate the reported bug.
Author
Owner

@jvanderaa commented on GitHub (May 22, 2020):

Updated

@jvanderaa commented on GitHub (May 22, 2020): Updated
Author
Owner

@jeremystretch commented on GitHub (Jun 1, 2020):

Closing due to inactivity. Please feel free to request reopening if you are able to provide full reproduction details without involving Docker or pynetbox.

@jeremystretch commented on GitHub (Jun 1, 2020): Closing due to inactivity. Please feel free to request reopening if you are able to provide full reproduction details without involving Docker or pynetbox.
Author
Owner

@jvanderaa commented on GitHub (Jun 2, 2020):

Please re-open. Last week was busy. The URL being called is:

From the Nornir inventory - https://github.com/nornir-automation/nornir/blob/develop/nornir/plugins/inventory/netbox.py

{nb_url}/api/dcim/devices/?limit=0

From the server logs, matching that:

[18/May/2020 17:40:20] "GET /api/dcim/devices/?limit=0 HTTP/1.1" 500 23895

Steps are provided in the updated description.

@jvanderaa commented on GitHub (Jun 2, 2020): Please re-open. Last week was busy. The URL being called is: From the Nornir inventory - https://github.com/nornir-automation/nornir/blob/develop/nornir/plugins/inventory/netbox.py ```python {nb_url}/api/dcim/devices/?limit=0 ``` From the server logs, matching that: ``` [18/May/2020 17:40:20] "GET /api/dcim/devices/?limit=0 HTTP/1.1" 500 23895 ``` Steps are provided in the updated description.
Author
Owner

@stale[bot] commented on GitHub (Jun 16, 2020):

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. Please see our contributing guide.

@stale[bot] commented on GitHub (Jun 16, 2020): 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. Please see our [contributing guide](https://github.com/netbox-community/netbox/blob/develop/CONTRIBUTING.md).
Author
Owner

@stale[bot] commented on GitHub (Jun 23, 2020):

This issue has been automatically closed due to lack of activity. In an effort to reduce noise, please do not comment any further. Note that the core maintainers may elect to reopen this issue at a later date if deemed necessary.

@stale[bot] commented on GitHub (Jun 23, 2020): This issue has been automatically closed due to lack of activity. In an effort to reduce noise, please do not comment any further. Note that the core maintainers may elect to reopen this issue at a later date if deemed necessary.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#3703