Editing multiple Interfaces - KeyError #3234

Closed
opened 2025-12-29 18:26:56 +01:00 by adam · 5 comments
Owner

Originally created by @kuhball on GitHub (Jan 28, 2020).

Originally assigned to: @jeremystretch on GitHub.

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.

Originally created by @kuhball on GitHub (Jan 28, 2020). Originally assigned to: @jeremystretch on GitHub. <!-- NOTE: This form is only for reproducible bugs. If you need assistance with NetBox installation, or if you have a general question, DO NOT open an issue. Instead, post to our mailing list: https://groups.google.com/forum/#!forum/netbox-discuss Please describe the environment in which you are running NetBox. Be sure that you are running an unmodified instance of the latest stable release before submitting a bug report. --> ### Environment * Python version: 3.7.3 * NetBox version: 2.7.2 <!-- Describe in detail the exact steps that someone else can take to reproduce this bug using the current stable release of NetBox (or the current beta release where applicable). 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 wrapper like pynetbox. --> ### Steps to Reproduce 1. Edit multiple interfaces from a device of choice 2. Set "mode" to "tagged" and add some vlans 3. Apply <!-- What did you expect to happen? --> ### Expected Behavior Tagged VLANs are saved in all interfaces <!-- What happened instead? --> ### Observed Behavior ``` <class 'TypeError'> Direct assignment to the forward side of a many-to-many set is prohibited. Use tagged_vlans.set() instead. ``` Stacktrace: ```[2020-01-28 14:57:10 +0000] [26] [DEBUG] POST /dcim/devices/1/interfaces/edit/ 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.
adam added the type: bugstatus: accepted labels 2025-12-29 18:26:56 +01:00
adam closed this issue 2025-12-29 18:26:57 +01:00
Author
Owner

@jeremystretch commented on GitHub (Jan 28, 2020):

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 commented on GitHub (Jan 28, 2020): 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.
Author
Owner

@jeremystretch commented on GitHub (Jan 28, 2020):

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

@jeremystretch commented on GitHub (Jan 28, 2020): @scouball The stack trace indicates a `KeyError` but you've posted a `TypeError` above; where are you seeing that?
Author
Owner

@jeremystretch commented on GitHub (Jan 28, 2020):

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

@jeremystretch commented on GitHub (Jan 28, 2020): This should be fixed in the next release, but please comment here if you encounter either exception again.
Author
Owner

@kuhball commented on GitHub (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.
@kuhball commented on GitHub (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. ```
Author
Owner

@DanSheps commented on GitHub (Jan 29, 2020):

Could you open a new issue for this?

Nevermind, could be related

@DanSheps commented on GitHub (Jan 29, 2020): ~~Could you open a new issue for this?~~ Nevermind, could be related
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#3234