Fix this validation thing, and we have to check existing actions

This commit is contained in:
shamoon
2026-08-18 09:45:28 -07:00
committed by GitHub
parent ea84c1dcd4
commit 202f2df9d4
2 changed files with 83 additions and 9 deletions
+24 -9
View File
@@ -3266,17 +3266,32 @@ class WorkflowSerializer(serializers.ModelSerializer[Workflow]):
def validate(self, attrs):
attrs = super().validate(attrs)
triggers = attrs.get("triggers") or []
actions = attrs.get("actions") or []
if "actions" in attrs:
has_remote_ocr_action = any(
action.get("type") == WorkflowAction.WorkflowActionType.REMOTE_OCR
for action in attrs["actions"]
)
else:
has_remote_ocr_action = self.instance is not None and (
self.instance.actions.filter(
type=WorkflowAction.WorkflowActionType.REMOTE_OCR,
).exists()
)
if "triggers" in attrs:
has_consumption_trigger = any(
trigger.get("type") == WorkflowTrigger.WorkflowTriggerType.CONSUMPTION
for trigger in attrs["triggers"]
)
else:
has_consumption_trigger = self.instance is not None and (
self.instance.triggers.filter(
type=WorkflowTrigger.WorkflowTriggerType.CONSUMPTION,
).exists()
)
# Remote OCR can only work with consumption triggers
if any(
action.get("type") == WorkflowAction.WorkflowActionType.REMOTE_OCR
for action in actions
) and not any(
trigger.get("type") == WorkflowTrigger.WorkflowTriggerType.CONSUMPTION
for trigger in triggers
):
if has_remote_ocr_action and not has_consumption_trigger:
raise serializers.ValidationError(
"Remote OCR actions require a consumption started trigger",
)