mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-14 01:41:22 -06:00
Fixes #4418: Fail cleanly when trying to import multiple device types simultaneously
This commit is contained in:
parent
aa38dcf490
commit
fb2868f8bb
@ -6,6 +6,10 @@
|
|||||||
|
|
||||||
* [#3676](https://github.com/netbox-community/netbox/issues/3676) - Reference VRF by name rather than RD during IP/prefix import
|
* [#3676](https://github.com/netbox-community/netbox/issues/3676) - Reference VRF by name rather than RD during IP/prefix import
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* [#4418](https://github.com/netbox-community/netbox/issues/4418) - Fail cleanly when trying to import multiple device types simultaneously
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## v2.7.11 (2020-03-27)
|
## v2.7.11 (2020-03-27)
|
||||||
|
@ -698,7 +698,7 @@ class ImportForm(BootstrapMixin, forms.Form):
|
|||||||
"""
|
"""
|
||||||
data = forms.CharField(
|
data = forms.CharField(
|
||||||
widget=forms.Textarea,
|
widget=forms.Textarea,
|
||||||
help_text="Enter object data in JSON or YAML format."
|
help_text="Enter object data in JSON or YAML format. Note: Only a single object/document is supported."
|
||||||
)
|
)
|
||||||
format = forms.ChoiceField(
|
format = forms.ChoiceField(
|
||||||
choices=(
|
choices=(
|
||||||
@ -717,14 +717,24 @@ class ImportForm(BootstrapMixin, forms.Form):
|
|||||||
if format == 'json':
|
if format == 'json':
|
||||||
try:
|
try:
|
||||||
self.cleaned_data['data'] = json.loads(data)
|
self.cleaned_data['data'] = json.loads(data)
|
||||||
|
# Check for multiple JSON objects
|
||||||
|
if type(self.cleaned_data['data']) is not dict:
|
||||||
|
raise forms.ValidationError({
|
||||||
|
'data': "Import is limited to one object at a time."
|
||||||
|
})
|
||||||
except json.decoder.JSONDecodeError as err:
|
except json.decoder.JSONDecodeError as err:
|
||||||
raise forms.ValidationError({
|
raise forms.ValidationError({
|
||||||
'data': "Invalid JSON data: {}".format(err)
|
'data': "Invalid JSON data: {}".format(err)
|
||||||
})
|
})
|
||||||
else:
|
else:
|
||||||
|
# Check for multiple YAML documents
|
||||||
|
if '\n---' in data:
|
||||||
|
raise forms.ValidationError({
|
||||||
|
'data': "Import is limited to one object at a time."
|
||||||
|
})
|
||||||
try:
|
try:
|
||||||
self.cleaned_data['data'] = yaml.load(data, Loader=yaml.SafeLoader)
|
self.cleaned_data['data'] = yaml.load(data, Loader=yaml.SafeLoader)
|
||||||
except yaml.scanner.ScannerError as err:
|
except yaml.error.YAMLError as err:
|
||||||
raise forms.ValidationError({
|
raise forms.ValidationError({
|
||||||
'data': "Invalid YAML data: {}".format(err)
|
'data': "Invalid YAML data: {}".format(err)
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user