Skip to content

Bulk Import: Non-unique related field value leads to 500 error #17498

Closed
@amyasnikov

Description

@amyasnikov

Deployment Type

Self-hosted

NetBox Version

v4.1.1

Python Version

3.10

Steps to Reproduce

  1. Create two manufacturers with the same description equal to "d"
  2. Go to Devices > Device Types > Import and enter the following:
manufacturer.description,model,slug,u_height
d,m1,m1,1
  1. Press "Submit" and get 500 error

Expected Behavior

GUI must provide meaningful error instead of just failing with 500. Something like "Found duplicate value d for manufacturer.description. Only unique values are supported".

Observed Behavior

dcim.models.devices.Manufacturer.MultipleObjectsReturned is raised

netbox-1  | Internal Server Error: /dcim/device-types/import/
netbox-1  | Traceback (most recent call last):
netbox-1  |   File "/usr/local/lib/python3.10/site-packages/django/core/handlers/exception.py", line 55, in inner
netbox-1  |     response = get_response(request)
netbox-1  |   File "/usr/local/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response
netbox-1  |     response = wrapped_callback(request, *callback_args, **callback_kwargs)
netbox-1  |   File "/usr/local/lib/python3.10/site-packages/django/views/generic/base.py", line 104, in view
netbox-1  |     return self.dispatch(request, *args, **kwargs)
netbox-1  |   File "/opt/netbox/netbox/netbox/views/generic/base.py", line 77, in dispatch
netbox-1  |     return super().dispatch(request, *args, **kwargs)
netbox-1  |   File "/opt/netbox/netbox/utilities/views.py", line 125, in dispatch
netbox-1  |     return super().dispatch(request, *args, **kwargs)
netbox-1  |   File "/opt/netbox/netbox/utilities/views.py", line 39, in dispatch
netbox-1  |     return super().dispatch(request, *args, **kwargs)
netbox-1  |   File "/usr/local/lib/python3.10/site-packages/django/views/generic/base.py", line 143, in dispatch
netbox-1  |     return handler(request, *args, **kwargs)
netbox-1  |   File "/opt/netbox/netbox/netbox/views/generic/bulk_views.py", line 494, in post
netbox-1  |     new_objs = self.create_and_update_objects(form, request)
netbox-1  |   File "/opt/netbox/netbox/netbox/views/generic/bulk_views.py", line 452, in create_and_update_objects
netbox-1  |     if model_form.is_valid():
netbox-1  |   File "/usr/local/lib/python3.10/site-packages/django/forms/forms.py", line 197, in is_valid
netbox-1  |     return self.is_bound and not self.errors
netbox-1  |   File "/usr/local/lib/python3.10/site-packages/django/forms/forms.py", line 192, in errors
netbox-1  |     self.full_clean()
netbox-1  |   File "/usr/local/lib/python3.10/site-packages/django/forms/forms.py", line 327, in full_clean
netbox-1  |     self._clean_fields()
netbox-1  |   File "/usr/local/lib/python3.10/site-packages/django/forms/forms.py", line 339, in _clean_fields
netbox-1  |     value = field.clean(value)
netbox-1  |   File "/usr/local/lib/python3.10/site-packages/django/forms/fields.py", line 204, in clean
netbox-1  |     value = self.to_python(value)
netbox-1  |   File "/usr/local/lib/python3.10/site-packages/django/forms/models.py", line 1557, in to_python
netbox-1  |     value = self.queryset.get(**{key: value})
netbox-1  |   File "/usr/local/lib/python3.10/site-packages/django/db/models/query.py", line 652, in get
netbox-1  |     raise self.model.MultipleObjectsReturned(
netbox-1  | dcim.models.devices.Manufacturer.MultipleObjectsReturned: get() returned more than one Manufacturer -- it returned 2!
netbox-1  | [15/Sep/2024 15:47:51] "POST /dcim/device-types/import/ HTTP/1.1" 500 158467

Metadata

Metadata

Assignees

Labels

severity: lowDoes not significantly disrupt application functionality, or a workaround is availablestatus: acceptedThis issue has been accepted for implementationtype: bugA confirmed report of unexpected behavior in the application

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions