diff --git a/netbox/core/api/serializers.py b/netbox/core/api/serializers.py index 0bdd9e427..0d743d952 100644 --- a/netbox/core/api/serializers.py +++ b/netbox/core/api/serializers.py @@ -1,5 +1,3 @@ -from django.core.exceptions import ValidationError -from django.utils.translation import gettext_lazy as _ from rest_framework import serializers from core.choices import * @@ -41,13 +39,6 @@ class DataSourceSerializer(NetBoxModelSerializer): 'parameters', 'ignore_rules', 'created', 'last_updated', 'file_count', ] - def clean(self): - - if self.type and self.type not in get_data_backend_choices(): - raise ValidationError({ - 'type': _("Unknown backend type: {type}".format(type=self.type)) - }) - class DataFileSerializer(NetBoxModelSerializer): url = serializers.HyperlinkedIdentityField( diff --git a/netbox/core/models/data.py b/netbox/core/models/data.py index fd250bce3..fb764134a 100644 --- a/netbox/core/models/data.py +++ b/netbox/core/models/data.py @@ -118,6 +118,12 @@ class DataSource(JobsMixin, PrimaryModel): def clean(self): + # Validate data backend type + if self.type and self.type not in registry['data_backends']: + raise ValidationError({ + 'type': _("Unknown backend type: {type}".format(type=self.type)) + }) + # Ensure URL scheme matches selected type if self.backend_class.is_local and self.url_scheme not in ('file', ''): raise ValidationError({