mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-16 04:02:52 -06:00
Extend _clean_fields to catch MultipleObjectsReturned and display a toast with a useful message instead of a 500 error
This commit is contained in:
parent
6b219a279b
commit
50fc15fadb
@ -2,6 +2,7 @@ import json
|
|||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
|
from django.core.exceptions import MultipleObjectsReturned
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
@ -99,6 +100,12 @@ class NetBoxModelImportForm(CSVModelForm, NetBoxModelForm):
|
|||||||
def _get_form_field(self, customfield):
|
def _get_form_field(self, customfield):
|
||||||
return customfield.to_form_field(for_csv_import=True)
|
return customfield.to_form_field(for_csv_import=True)
|
||||||
|
|
||||||
|
def _clean_fields(self):
|
||||||
|
try:
|
||||||
|
return super()._clean_fields()
|
||||||
|
except MultipleObjectsReturned as e:
|
||||||
|
self.add_error(None, f'A non-unique value was provided for one or more fields: {e}')
|
||||||
|
|
||||||
|
|
||||||
class NetBoxModelBulkEditForm(CustomFieldsMixin, forms.Form):
|
class NetBoxModelBulkEditForm(CustomFieldsMixin, forms.Form):
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user