Netbox: can't clear selection custom field

Created on 21 Mar 2018  路  3Comments  路  Source: netbox-community/netbox

Issue type

[ ] Feature request
[x] Bug report
[ ] Documentation

Environment

  • Python version: 2.7.5
  • NetBox version: 2.3.1

Description

Assuming there is a basic setup of manufacturer, sites, a device and so on.

  1. create a custom selection field with a couple of options
  2. edit an device and set the field, save
  3. edit the same device and try to clear the field (select ------), save
  4. receive an error 500 page :(

Sadly I can't reproduce this in the docker-compose setup.

Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/django/core/handlers/exception.py", line 41, in inner
    response = get_response(request)
  File "/usr/lib/python2.7/site-packages/django/core/handlers/base.py", line 187, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/usr/lib/python2.7/site-packages/django/core/handlers/base.py", line 185, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/usr/lib/python2.7/site-packages/django/views/generic/base.py", line 68, in view
    return self.dispatch(request, *args, **kwargs)
  File "/usr/lib/python2.7/site-packages/django/contrib/auth/mixins.py", line 92, in dispatch
    return super(PermissionRequiredMixin, self).dispatch(request, *args, **kwargs)
  File "/usr/lib/python2.7/site-packages/django/views/generic/base.py", line 88, in dispatch
    return handler(request, *args, **kwargs)
  File "/opt/netbox/netbox/utilities/views.py", line 196, in post
    obj = form.save()
  File "/opt/netbox/netbox/extras/forms.py", line 123, in save
    self._save_custom_fields()
  File "/opt/netbox/netbox/extras/forms.py", line 116, in _save_custom_fields
    cfv.save()
  File "/opt/netbox/netbox/extras/models.py", line 169, in save
    if self.pk and self.value is None:
  File "/opt/netbox/netbox/extras/models.py", line 161, in value
    return self.field.deserialize_value(self.serialized_value)
  File "/opt/netbox/netbox/extras/models.py", line 140, in deserialize_value
    return self.choices.get(pk=int(serialized_value))
ValueError: invalid literal for int() with base 10: ''

but funnily enough there is a check for exactly this case a few lines about the crash site:

if serialized_value is '':
    return None
accepted bug

All 3 comments

I just tested this on python 3.4 and did not get any errors. Given that it isn't reproducible in python 3.4 or on the docker setup, are you sure it isn't a problem with your setup somehow?

This bug affects only Python 2.

@luto I can confirm that your PR #1981 fixes the issue. I _believe_ the evaluation is performed using is because at one point the value was being compared against None rather than an empty string. Good catch!

This bug affects only Python 2

I only later noticed that the docker setup is running the more sane py3, which is why I couldn't reproduce it :man_facepalming: Thanks for the quick merge! :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

VictorJ76 picture VictorJ76  路  3Comments

bellwood picture bellwood  路  4Comments

candlerb picture candlerb  路  3Comments

benjy44 picture benjy44  路  3Comments

hellerve picture hellerve  路  3Comments