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 <noreply@anthropic.com>
This commit is contained in:
Arthur
2026-03-30 15:40:14 -07:00
parent cf41c45a26
commit 83fb0a6379
2 changed files with 2 additions and 4 deletions

View File

@@ -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

View File

@@ -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},