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

Closed
opened 2025-12-29 21:28:50 +01:00 by adam · 0 comments
Owner

Originally created by @amyasnikov on GitHub (Sep 15, 2024).

Originally assigned to: @bctiemann on GitHub.

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
Originally created by @amyasnikov on GitHub (Sep 15, 2024). Originally assigned to: @bctiemann on GitHub. ### 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 ``` 3. 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 ```
adam added the type: bugstatus: acceptedseverity: low labels 2025-12-29 21:28:50 +01:00
adam closed this issue 2025-12-29 21:28:50 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#10246