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: Unknown accessor for a related field leads to 500 error #17497

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

Bulk Import: Unknown accessor for a related field leads to 500 error #17497

amyasnikov opened this issue Sep 15, 2024 · 0 comments · Fixed by #17594
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. Go to Devices > Device Types > Import
  2. Enter the following content:
manufacturer.non_existing_field,model,slug,u_height
something,m1,m1,1
  1. Press "Submit" and get 500 error

The error persists for all the models with relations

Expected Behavior

GUI must provide meaningful error (something like "Manufacturer has no non_existing_field" field) instead of just failing with 500

Observed Behavior

500 error. Here is the traceback:

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 635, in get
netbox-1  |     clone = self._chain() if self.query.combinator else self.filter(*args, **kwargs)
netbox-1  |   File "/usr/local/lib/python3.10/site-packages/django/db/models/query.py", line 1476, in filter
netbox-1  |     return self._filter_or_exclude(False, args, kwargs)
netbox-1  |   File "/usr/local/lib/python3.10/site-packages/django/db/models/query.py", line 1494, in _filter_or_exclude
netbox-1  |     clone._filter_or_exclude_inplace(negate, args, kwargs)
netbox-1  |   File "/usr/local/lib/python3.10/site-packages/django/db/models/query.py", line 1501, in _filter_or_exclude_inplace
netbox-1  |     self._query.add_q(Q(*args, **kwargs))
netbox-1  |   File "/usr/local/lib/python3.10/site-packages/django/db/models/sql/query.py", line 1613, in add_q
netbox-1  |     clause, _ = self._add_q(q_object, self.used_aliases)
netbox-1  |   File "/usr/local/lib/python3.10/site-packages/django/db/models/sql/query.py", line 1645, in _add_q
netbox-1  |     child_clause, needed_inner = self.build_filter(
netbox-1  |   File "/usr/local/lib/python3.10/site-packages/django/db/models/sql/query.py", line 1495, in build_filter
netbox-1  |     lookups, parts, reffed_expression = self.solve_lookup_type(arg, summarize)
netbox-1  |   File "/usr/local/lib/python3.10/site-packages/django/db/models/sql/query.py", line 1307, in solve_lookup_type
netbox-1  |     _, field, _, lookup_parts = self.names_to_path(lookup_splitted, self.get_meta())
netbox-1  |   File "/usr/local/lib/python3.10/site-packages/django/db/models/sql/query.py", line 1772, in names_to_path
netbox-1  |     raise FieldError(
netbox-1  | django.core.exceptions.FieldError: Cannot resolve keyword 'non_existing_field' into field. Choices are: bookmarks, contacts, created, custom_field_data, description, device_types, id, inventory_item_templates, inventory_items, journal_entries, last_updated, module_types, name, platforms, rack_types, slug, subscriptions, tagged_items, tags
netbox-1  | [15/Sep/2024 15:32:44] "POST /dcim/device-types/import/ HTTP/1.1" 500 198842
@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
@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 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: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation status: accepted This issue has been accepted for implementation labels Sep 16, 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
bctiemann added a commit that referenced this issue Oct 11, 2024
…17594)

* Add handling for FieldError to CSVModelChoiceField.to_python to handle invalid accessor field

* manufacturer & default_platform should be CSVModelChoiceFields

* Fix string translation

---------

Co-authored-by: Jeremy Stretch <[email protected]>
jeremystretch added a commit to alehaa/netbox that referenced this issue Oct 11, 2024
…k import forms (netbox-community#17594)

* Add handling for FieldError to CSVModelChoiceField.to_python to handle invalid accessor field

* manufacturer & default_platform should be CSVModelChoiceFields

* Fix string translation

---------

Co-authored-by: Jeremy Stretch <[email protected]>
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
Development

Successfully merging a pull request may close this issue.

3 participants