From 3a421392c3daddca015c26db8ca7b95b5f31d3c5 Mon Sep 17 00:00:00 2001
From: ml bonhomme <bonhomme@teklia.com>
Date: Wed, 3 Jul 2024 15:49:59 +0000
Subject: [PATCH] Do not validate use_gpu when none is being sent in the
 request

---
 arkindex/process/serializers/worker_runs.py       | 10 ++++------
 arkindex/process/tests/test_workerruns_use_gpu.py |  2 +-
 2 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/arkindex/process/serializers/worker_runs.py b/arkindex/process/serializers/worker_runs.py
index 6687a0a5a4..47c2a0b4b5 100644
--- a/arkindex/process/serializers/worker_runs.py
+++ b/arkindex/process/serializers/worker_runs.py
@@ -218,15 +218,13 @@ class WorkerRunEditSerializer(WorkerRunSerializer):
         # Same as WorkerRunSerializer, but the worker_version_id cannot be edited
         fields = tuple(set(WorkerRunSerializer.Meta.fields) - {"worker_version_id"})
 
-    def validate(self, data):
-        data = super().validate(data)
-        use_gpu = data.get("use_gpu", False)
+    def validate_use_gpu(self, use_gpu):
         worker_version = self.instance.version
         if worker_version.gpu_usage == FeatureUsage.Disabled and use_gpu:
-            raise ValidationError({"use_gpu": ["This worker version does not support GPU usage."]})
+            raise ValidationError("This worker version does not support GPU usage.")
         if worker_version.gpu_usage == FeatureUsage.Required and not use_gpu:
-            raise ValidationError({"use_gpu": ["This worker version requires GPU usage."]})
-        return data
+            raise ValidationError("This worker version requires GPU usage.")
+        return use_gpu
 
 
 class UserWorkerRunSerializer(serializers.ModelSerializer):
diff --git a/arkindex/process/tests/test_workerruns_use_gpu.py b/arkindex/process/tests/test_workerruns_use_gpu.py
index 0d8f9663e2..fb14490533 100644
--- a/arkindex/process/tests/test_workerruns_use_gpu.py
+++ b/arkindex/process/tests/test_workerruns_use_gpu.py
@@ -174,7 +174,7 @@ class TestWorkerRunsGPU(FixtureAPITestCase):
                     parents=[]
                 )
                 self.assertEqual(run.use_gpu, True if worker_version.gpu_usage == FeatureUsage.Required else False)
-                with self.assertNumQueries(4):
+                with self.assertNumQueries(3):
                     response = self.client.patch(
                         reverse("api:worker-run-details", kwargs={"pk": str(run.id)}),
                         data={"use_gpu": use_gpu}
-- 
GitLab