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

Fixes: #17497 - Handle invalid accessor fields in bulk import forms #17594

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions netbox/dcim/forms/bulk_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,13 +367,13 @@ class Meta:


class DeviceTypeImportForm(NetBoxModelImportForm):
manufacturer = forms.ModelChoiceField(
manufacturer = CSVModelChoiceField(
label=_('Manufacturer'),
queryset=Manufacturer.objects.all(),
to_field_name='name',
help_text=_('The manufacturer which produces this device type')
)
default_platform = forms.ModelChoiceField(
default_platform = CSVModelChoiceField(
label=_('Default platform'),
queryset=Platform.objects.all(),
to_field_name='name',
Expand Down
6 changes: 5 additions & 1 deletion netbox/utilities/forms/fields/csv.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django import forms
from django.utils.translation import gettext_lazy as _
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import MultipleObjectsReturned, ObjectDoesNotExist
from django.core.exceptions import MultipleObjectsReturned, ObjectDoesNotExist, FieldError
from django.db.models import Q

from utilities.choices import unpack_grouped_choices
Expand Down Expand Up @@ -64,6 +64,10 @@ def to_python(self, value):
raise forms.ValidationError(
_('"{value}" is not a unique value for this field; multiple objects were found').format(value=value)
)
except FieldError:
raise forms.ValidationError(
_('"{field_name}" is an invalid accessor field name.').format(field_name=self.to_field_name)
)


class CSVModelMultipleChoiceField(forms.ModelMultipleChoiceField):
Expand Down