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

Fixed error display on parent import form #15213

Merged
merged 2 commits into from
Feb 21, 2024
Merged
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
13 changes: 8 additions & 5 deletions netbox/netbox/views/generic/bulk_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ def _get_form_fields(self):
if type(field.widget) is not HiddenInput
}

def _save_object(self, model_form, request):
def _save_object(self, import_form, model_form, request):

# Save the primary object
obj = self.save_object(model_form, request)
Expand All @@ -346,11 +346,14 @@ def _save_object(self, model_form, request):
related_obj = f.save()
related_obj_pks.append(related_obj.pk)
else:
# Replicate errors on the related object form to the primary form for display
# Replicate errors on the related object form to the import form for display and abort
for subfield_name, errors in f.errors.items():
for err in errors:
err_msg = "{}[{}] {}: {}".format(field_name, i, subfield_name, err)
model_form.add_error(None, err_msg)
if subfield_name == '__all__':
err_msg = f"{field_name}[{i}]: {err}"
else:
err_msg = f"{field_name}[{i}] {subfield_name}: {err}"
import_form.add_error(None, err_msg)
raise AbortTransaction()

# Enforce object-level permissions on related objects
Expand Down Expand Up @@ -417,7 +420,7 @@ def create_and_update_objects(self, form, request):
restrict_form_fields(model_form, request.user)

if model_form.is_valid():
obj = self._save_object(model_form, request)
obj = self._save_object(form, model_form, request)
saved_objects.append(obj)
else:
# Replicate model form errors for display
Expand Down
Loading