Skip to content

Editing multiple Interfaces - KeyError #4030

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

Closed
kuhball opened this issue Jan 28, 2020 · 5 comments
Closed

Editing multiple Interfaces - KeyError #4030

kuhball opened this issue Jan 28, 2020 · 5 comments
Assignees
Labels
status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application

Comments

@kuhball
Copy link

kuhball commented Jan 28, 2020

Environment

  • Python version: 3.7.3
  • NetBox version: 2.7.2

Steps to Reproduce

  1. Edit multiple interfaces from a device of choice
  2. Set "mode" to "tagged" and add some vlans
  3. Apply

Expected Behavior

Tagged VLANs are saved in all interfaces

Observed Behavior

<class 'TypeError'>

Direct assignment to the forward side of a many-to-many set is prohibited. Use tagged_vlans.set() instead.

Stacktrace:

netbox_1         | 14:57:10: Internal Server Error: /dcim/devices/1/interfaces/edit/
netbox_1         | Traceback (most recent call last):
netbox_1         |   File "/usr/local/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
netbox_1         |     response = get_response(request)
netbox_1         |   File "/usr/local/lib/python3.7/site-packages/django/core/handlers/base.py", line 115, in _get_response
netbox_1         |     response = self.process_exception_by_middleware(e, request)
netbox_1         |   File "/usr/local/lib/python3.7/site-packages/django/core/handlers/base.py", line 113, in _get_response
netbox_1         |     response = wrapped_callback(request, *callback_args, **callback_kwargs)
netbox_1         |   File "/usr/local/lib/python3.7/site-packages/django/views/generic/base.py", line 71, in view
netbox_1         |     return self.dispatch(request, *args, **kwargs)
netbox_1         |   File "/usr/local/lib/python3.7/site-packages/django/contrib/auth/mixins.py", line 85, in dispatch
netbox_1         |     return super().dispatch(request, *args, **kwargs)
netbox_1         |   File "/usr/local/lib/python3.7/site-packages/django/views/generic/base.py", line 97, in dispatch
netbox_1         |     return handler(request, *args, **kwargs)
netbox_1         |   File "/opt/netbox/netbox/utilities/views.py", line 638, in post
netbox_1         |     if form.is_valid():
netbox_1         |   File "/usr/local/lib/python3.7/site-packages/django/forms/forms.py", line 185, in is_valid
netbox_1         |     return self.is_bound and not self.errors
netbox_1         |   File "/usr/local/lib/python3.7/site-packages/django/forms/forms.py", line 180, in errors
netbox_1         |     self.full_clean()
netbox_1         |   File "/usr/local/lib/python3.7/site-packages/django/forms/forms.py", line 382, in full_clean
netbox_1         |     self._clean_form()
netbox_1         |   File "/usr/local/lib/python3.7/site-packages/django/forms/forms.py", line 409, in _clean_form
netbox_1         |     cleaned_data = self.clean()
netbox_1         |   File "/opt/netbox/netbox/dcim/forms.py", line 112, in clean
netbox_1         |     valid_sites = [None, self.cleaned_data['device'].site]
netbox_1         | KeyError: 'device'

Tested this in a fresh docker environment. Worked with 2.6.X.

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

This looks like a regression introduced under #3589. We probably need to split out the VLAN validation, since we have no context of a specific device/site when bulk editing interfaces.

@jeremystretch
Copy link
Member

@scouball The stack trace indicates a KeyError but you've posted a TypeError above; where are you seeing that?

@jeremystretch
Copy link
Member

This should be fixed in the next release, but please comment here if you encounter either exception again.

@kuhball
Copy link
Author

kuhball commented Jan 29, 2020

Thanks for the quick fix! I'm not sure what happened with the KeyError and TypeError, this only occurred in the docker environment. If needed I can investigate further.

The same issue still happens with the "tagged all" option:

Environment:


Request Method: POST
Request URL: http://netbox.labhh.alocal/dcim/devices/8/interfaces/edit/?return_url=/dcim/devices/8/

Django Version: 2.2.9
Python Version: 3.7.3
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.humanize',
 'cacheops',
 'corsheaders',
 'debug_toolbar',
 'django_filters',
 'django_rq',
 'django_tables2',
 'django_prometheus',
 'mptt',
 'rest_framework',
 'taggit',
 'taggit_serializer',
 'timezone_field',
 'circuits',
 'dcim',
 'ipam',
 'extras',
 'secrets',
 'tenancy',
 'users',
 'utilities',
 'virtualization',
 'drf_yasg']
Installed Middleware:
('debug_toolbar.middleware.DebugToolbarMiddleware',
 'django_prometheus.middleware.PrometheusBeforeMiddleware',
 'corsheaders.middleware.CorsMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'django.middleware.security.SecurityMiddleware',
 'utilities.middleware.ExceptionHandlingMiddleware',
 'utilities.middleware.LoginRequiredMiddleware',
 'utilities.middleware.APIVersionMiddleware',
 'extras.middleware.ObjectChangeMiddleware',
 'django_prometheus.middleware.PrometheusAfterMiddleware')



Traceback:

File "/srv/netbox/current/venv-py3/lib/python3.7/site-packages/django/core/handlers/exception.py" in inner
  34.             response = get_response(request)

File "/srv/netbox/current/venv-py3/lib/python3.7/site-packages/django/core/handlers/base.py" in _get_response
  115.                 response = self.process_exception_by_middleware(e, request)

File "/srv/netbox/current/venv-py3/lib/python3.7/site-packages/django/core/handlers/base.py" in _get_response
  113.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/srv/netbox/current/venv-py3/lib/python3.7/site-packages/django/views/generic/base.py" in view
  71.             return self.dispatch(request, *args, **kwargs)

File "/srv/netbox/current/venv-py3/lib/python3.7/site-packages/django/contrib/auth/mixins.py" in dispatch
  85.         return super().dispatch(request, *args, **kwargs)

File "/srv/netbox/current/venv-py3/lib/python3.7/site-packages/django/views/generic/base.py" in dispatch
  97.         return handler(request, *args, **kwargs)

File "./utilities/views.py" in post
  660.                                     setattr(obj, name, form.cleaned_data[name])

File "/srv/netbox/current/venv-py3/lib/python3.7/site-packages/django/db/models/fields/related_descriptors.py" in __set__
  538.             % self._get_set_deprecation_msg_params(),

Exception Type: TypeError at /dcim/devices/8/interfaces/edit/
Exception Value: Direct assignment to the forward side of a many-to-many set is prohibited. Use tagged_vlans.set() instead.

@DanSheps
Copy link
Member

DanSheps commented Jan 29, 2020

Could you open a new issue for this?

Nevermind, could be related

@jeremystretch jeremystretch reopened this Jan 29, 2020
@jeremystretch jeremystretch self-assigned this Jan 30, 2020
@jeremystretch jeremystretch pinned this issue Jan 30, 2020
@jeremystretch jeremystretch unpinned this issue Feb 5, 2020
@lock lock bot locked as resolved and limited conversation to collaborators May 5, 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

No branches or pull requests

3 participants