Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't clear selection custom field #1980

Closed
luto opened this issue Mar 21, 2018 · 3 comments · Fixed by #1981
Closed

can't clear selection custom field #1980

luto opened this issue Mar 21, 2018 · 3 comments · Fixed by #1981
Labels
status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application

Comments

@luto
Copy link
Contributor

luto commented Mar 21, 2018

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
@DanSheps
Copy link
Member

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?

@jeremystretch jeremystretch added type: bug A confirmed report of unexpected behavior in the application status: accepted This issue has been accepted for implementation labels Mar 21, 2018
@jeremystretch
Copy link
Member

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!

@luto
Copy link
Contributor Author

luto commented Mar 21, 2018

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 🤦‍♂️ Thanks for the quick merge! :)

@lock lock bot locked as resolved and limited conversation to collaborators Jan 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants