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

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

Closed
amyasnikov opened this issue Sep 15, 2024 · 0 comments · Fixed by #17593
Closed

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

amyasnikov opened this issue Sep 15, 2024 · 0 comments · Fixed by #17593
Assignees
Labels
severity: low Does not significantly disrupt application functionality, or a workaround is available status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application

Comments

@amyasnikov
Copy link
Contributor

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
@amyasnikov amyasnikov added status: needs triage This issue is awaiting triage by a maintainer type: bug A confirmed report of unexpected behavior in the application labels Sep 15, 2024
@amyasnikov amyasnikov changed the title Bulk Import: Non-unique field value leads to 500 error Bulk Import: Non-unique related field value leads to 500 error Sep 15, 2024
@arthanson arthanson added status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation severity: low Does not significantly disrupt application functionality, or a workaround is available status: accepted This issue has been accepted for implementation and removed status: needs triage This issue is awaiting triage by a maintainer status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation labels Sep 16, 2024
@arthanson arthanson self-assigned this Sep 16, 2024
@arthanson arthanson added status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation and removed status: accepted This issue has been accepted for implementation labels Sep 19, 2024
@arthanson arthanson removed their assignment Sep 19, 2024
@bctiemann bctiemann self-assigned this Sep 24, 2024
@bctiemann bctiemann added status: accepted This issue has been accepted for implementation and removed status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation labels Sep 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
severity: low Does not significantly disrupt application functionality, or a workaround is available status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
3 participants