diff --git a/src/documents/serialisers.py b/src/documents/serialisers.py index 1a491c5a4..e47f42e09 100644 --- a/src/documents/serialisers.py +++ b/src/documents/serialisers.py @@ -3213,6 +3213,13 @@ class WorkflowActionSerializer(serializers.ModelSerializer[WorkflowAction]): {"assign_title": f'Invalid f-string detected: "{e.args[0]}"'}, ) + if attrs.get("assign_custom_fields_values"): + # Empty strings treated as None to avoid unexpected behavior + attrs["assign_custom_fields_values"] = { + field_id: (None if value == "" else value) + for field_id, value in attrs["assign_custom_fields_values"].items() + } + if ( "type" in attrs and attrs["type"] == WorkflowAction.WorkflowActionType.EMAIL diff --git a/src/documents/tests/test_api_workflows.py b/src/documents/tests/test_api_workflows.py index cdd3a5f40..e2689001a 100644 --- a/src/documents/tests/test_api_workflows.py +++ b/src/documents/tests/test_api_workflows.py @@ -422,6 +422,11 @@ class TestApiWorkflows(DirectoriesMixin, APITestCase): json.dumps( { "assign_title": "", + "assign_custom_fields": [self.cf1.id, self.cf2.id], + "assign_custom_fields_values": { + str(self.cf1.id): "", + str(self.cf2.id): 0, + }, }, ), content_type="application/json", @@ -429,6 +434,10 @@ class TestApiWorkflows(DirectoriesMixin, APITestCase): self.assertEqual(response.status_code, status.HTTP_201_CREATED) action = WorkflowAction.objects.get(id=response.data["id"]) self.assertIsNone(action.assign_title) + self.assertEqual( + action.assign_custom_fields_values, + {str(self.cf1.id): None, str(self.cf2.id): 0}, + ) response = self.client.post( self.ENDPOINT_TRIGGERS,