From 83fb0a637992bb1db9ce3efa420710bf2e5c307f Mon Sep 17 00:00:00 2001 From: Arthur Date: Mon, 30 Mar 2026 15:40:14 -0700 Subject: [PATCH] Align API validation messages with UI; restore complete checks - Match UI error messages for upload+data_file conflict and no-source case - Keep API-only guards for upload+data_source and data_source-without-data_file - Restore test_upload_with_data_source_fails Co-Authored-By: Claude Sonnet 4.6 --- netbox/extras/api/serializers_/scripts.py | 4 ++-- netbox/extras/tests/test_api.py | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/netbox/extras/api/serializers_/scripts.py b/netbox/extras/api/serializers_/scripts.py index f054a6a37..d13a9aa08 100644 --- a/netbox/extras/api/serializers_/scripts.py +++ b/netbox/extras/api/serializers_/scripts.py @@ -51,7 +51,7 @@ class ScriptModuleSerializer(ValidatedModelSerializer): if upload_file and has_data_file: raise serializers.ValidationError( - _("Cannot upload a file and sync from an existing data file.") + _("Cannot upload a file and sync from an existing file") ) if upload_file and has_data_source: raise serializers.ValidationError( @@ -63,7 +63,7 @@ class ScriptModuleSerializer(ValidatedModelSerializer): ) if self.instance is None and not upload_file and not has_data_file: raise serializers.ValidationError( - _("Must upload a file or provide a data source and data file to sync.") + _("Must upload a file or select a data file to sync") ) return data diff --git a/netbox/extras/tests/test_api.py b/netbox/extras/tests/test_api.py index 650ecfcf6..b49330cae 100644 --- a/netbox/extras/tests/test_api.py +++ b/netbox/extras/tests/test_api.py @@ -1431,8 +1431,6 @@ class ScriptUploadTest(APITestCase): self.add_permissions('extras.add_scriptmodule', 'core.add_managedfile') script_content = b"from extras.scripts import Script\nclass TestScript(Script):\n pass\n" upload_file = SimpleUploadedFile('test_upload.py', script_content, content_type='text/plain') - # data_source is intentionally a raw value to exercise the multipart path where DRF's - # nested-serializer HTML parser drops the field; validation must still catch the conflict. response = self.client.post( self.url_list, {'upload_file': upload_file, 'data_source': 1},