From f0543742a7873325c1ff5ea6824fc08e03294f97 Mon Sep 17 00:00:00 2001
From: Erwan Rouchet <rouchet@teklia.com>
Date: Tue, 26 Mar 2024 11:52:17 +0100
Subject: [PATCH] Restore set_elements on update responses

---
 arkindex/training/api.py | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/arkindex/training/api.py b/arkindex/training/api.py
index c77e858fe8..b167ea914f 100644
--- a/arkindex/training/api.py
+++ b/arkindex/training/api.py
@@ -716,6 +716,17 @@ class DatasetUpdate(ACLMixin, RetrieveUpdateDestroyAPIView):
         if obj.state == DatasetState.Complete:
             raise ValidationError(detail="This dataset is in complete state and cannot be modified anymore.")
 
+    def update(self, request, *args, **kwargs):
+        # Do exactly the same thing as what DRF does, but without the automatic prefetch cache removal:
+        # https://github.com/encode/django-rest-framework/blob/2da473c8c8e024e80c13a624782f1da6272812da/rest_framework/mixins.py#L70
+        # This allows `set_elements` to still be returned after the update.
+        partial = kwargs.pop("partial", False)
+        instance = self.get_object()
+        serializer = self.get_serializer(instance, data=request.data, partial=partial)
+        serializer.is_valid(raise_exception=True)
+        self.perform_update(serializer)
+        return Response(serializer.data)
+
     def perform_destroy(self, dataset):
         DatasetElement.objects.filter(set__dataset_id=dataset.id).delete()
         dataset.sets.all().delete()
-- 
GitLab