Require data_file when data_source is specified

data_source alone is not a valid creation payload — a data_file must
also be provided to identify which file within the source to sync.
Add the corresponding validation error and a test to cover the case.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Arthur
2026-03-30 15:36:51 -07:00
parent 3bd2dbea86
commit f9af8e2068
2 changed files with 17 additions and 2 deletions

View File

@@ -57,9 +57,13 @@ class ScriptModuleSerializer(ValidatedModelSerializer):
raise serializers.ValidationError(
_("Cannot upload a file and sync from a data source.")
)
if self.instance is None and not upload_file and not has_data_file and not has_data_source:
if has_data_source and not has_data_file:
raise serializers.ValidationError(
_("Must upload a file or provide a data source or data file to sync.")
_("A data file must be specified when syncing from a data source.")
)
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.")
)
return data

View File

@@ -1441,6 +1441,17 @@ class ScriptUploadTest(APITestCase):
)
self.assertHttpStatus(response, status.HTTP_400_BAD_REQUEST)
def test_data_source_without_data_file_fails(self):
"""data_source alone (without data_file) must be rejected."""
self.add_permissions('extras.add_scriptmodule', 'core.add_managedfile')
response = self.client.post(
self.url_list,
{'data_source': 1},
format='multipart',
**self.header,
)
self.assertHttpStatus(response, status.HTTP_400_BAD_REQUEST)
def test_upload_script_module_without_file_fails(self):
self.add_permissions('extras.add_scriptmodule', 'core.add_managedfile')
response = self.client.post(self.url_list, {}, format='json', **self.header)