Skip to content

Commit 653acbf

Browse files
committed
#4347: Changelog & cleanup
1 parent 93e7457 commit 653acbf

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

docs/release-notes/version-3.4.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717

1818
NetBox's global search functionality has been completely overhauled and replaced by a new cache-based lookup.
1919

20+
### JSON/YAML Bulk Imports ([#4347](https://github.com/netbox-community/netbox/issues/4347))
21+
22+
NetBox's bulk import feature, which was previously limited to CSV-formatted data for most objects, has been extended to support the import of objects from JSON and/or YAML data as well.
23+
2024
#### CSV-Based Bulk Updates ([#7961](https://github.com/netbox-community/netbox/issues/7961))
2125

2226
NetBox's CSV-based bulk import functionality has been extended to support also modifying existing objects. When an `id` column is present in the import form, it will be used to infer the object to be modified, rather than a new object being created. All fields (columns) are optional when modifying existing objects.

netbox/netbox/views/generic/bulk_views.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -375,19 +375,14 @@ def create_and_update_objects(self, form, request):
375375
form.add_error('data', f"Row {i}: Object with ID {object_id} does not exist")
376376
raise ValidationError('')
377377

378+
# Instantiate the model form for the object
379+
model_form_kwargs = {
380+
'data': record,
381+
'instance': instance,
382+
}
378383
if form.cleaned_data['format'] == ImportFormatChoices.CSV:
379-
model_form = self.model_form(record, instance=instance, headers=form._csv_headers)
380-
else:
381-
model_form = self.model_form(record, instance=instance)
382-
# Assign default values for any fields which were not specified.
383-
# We have to do this manually because passing 'initial=' to the form
384-
# on initialization merely sets default values for the widgets.
385-
# Since widgets are not used for YAML/JSON import, we first bind the
386-
# imported data normally, then update the form's data with the applicable
387-
# field defaults as needed prior to form validation.
388-
for field_name, field in model_form.fields.items():
389-
if field_name not in record and hasattr(field, 'initial'):
390-
model_form.data[field_name] = field.initial
384+
model_form_kwargs['headers'] = form._csv_headers
385+
model_form = self.model_form(**model_form_kwargs)
391386

392387
# When updating, omit all form fields other than those specified in the record. (No
393388
# fields are required when modifying an existing object.)

0 commit comments

Comments
 (0)