diff --git a/arkindex/training/api.py b/arkindex/training/api.py index 87102286674075025f500298335d4e5e140f188c..3adbe5b8975d33daf4886d04a9a0de5a0d25fdcf 100644 --- a/arkindex/training/api.py +++ b/arkindex/training/api.py @@ -793,7 +793,7 @@ class DatasetClone(CorpusACLMixin, CreateAPIView): clone = copy.copy(dataset) # Make Django think it is a new dataset that it should insert clone.id = None - clone.name = clone_name + clone.name = clone_name[:100] clone.state = DatasetState.Open clone.creator = request.user clone.save() diff --git a/arkindex/training/tests/test_datasets_api.py b/arkindex/training/tests/test_datasets_api.py index 45ba11bf3e1281e054237070b36458c6df250ef5..70880b137d9725d7954d6fc31aead3808ade8a45 100644 --- a/arkindex/training/tests/test_datasets_api.py +++ b/arkindex/training/tests/test_datasets_api.py @@ -1518,6 +1518,21 @@ class TestDatasetsAPI(FixtureAPITestCase): 'task_id': None, }, ) + + def test_clone_name_too_long(self): + dataset = self.corpus.datasets.create(name='A' * 99, creator=self.user) + self.client.force_login(self.user) + with self.assertNumQueries(13): + response = self.client.post( + reverse('api:dataset-clone', kwargs={'pk': dataset.id}), + format='json', + ) + self.assertEqual(response.status_code, status.HTTP_201_CREATED) + data = response.json() + clone = Dataset.objects.get(id=data.pop('id')) + self.assertEqual(clone.name, 'Clone of ' + 'A' * 91) + self.assertEqual(data['name'], clone.name) + # DatasetElementDestroy def test_destroy_dataset_element_requires_login(self):