Nested do task detected - ignoring #582
|
Hi! @mrsimonemms I have an anchor that contains the main logic of my workflow. If I do it this way: .anchors:
notificationSendSteps: ¬ificationSendSteps
- initData:
set:
version: "1.0.0"
- handleValidateInputError:
do:
- guardInput:
switch:
- invalid:
when: ${ $data.ntf_code == "code" }
then: continue
- default:
then: exit
- fault:
raise:
error:
type: error
status: 400
title: Invalid notification.create event
detail: Some detailsI see the following line in the logs at the debug level: And the function is completely ignored during execution. But if you swap these two functions, everything works properly: - handleValidateInputError:
do:
- guardInput:
switch:
- invalid:
when: ${ $data.ntf_code == "code" }
then: continue
- default:
then: exit
- fault:
raise:
error:
type: error
status: 400
title: Invalid notification.create event
detail: Some details
- initData:
set:
version: "1.0.0"There is no message about ignoring in the logs, and the logic works correctly. My code is anonymized. Can you suggest the reason for this behavior and how the logic I described above can be achieved? Thanks! |
Replies: 2 comments
|
Hi @PavelVydysh, yes this is by design. The
The reality is that there is a bit of a rough edge here that the code has to make a couple of assumptions and it does it by going on the order the tasks are presented in, which is what you're seeing. See the code for the how. In reality, you shouldn't be putting a nested .anchors:
# A flat task list. Every task here is a sibling in the SAME scope, which is
# what keeps this a single registered workflow (and therefore a single
# Temporal Workflow Execution). Do NOT wrap the validation in a nested `do`:
# a `do` task at the root level is registered as a separate workflow type.
notificationSendSteps: ¬ificationSendSteps
- initData:
set:
version: "1.0.0"
# ... any number of other tasks may sit here ...
# Validation gate. Add further checks as additional cases; each one that
# indicates a problem redirects to the failure path below. The `default`
# case is the happy path and jumps OVER that failure path.
#
# Note: `exit` is deliberately not used. At the top level of a workflow
# there is no enclosing scope, so `exit` behaves like `end` and would skip
# every remaining task, not just the failure path.
- guardInput:
switch:
- missingCode:
when: ${ $data.ntf_code == "code" }
then: validationFailed
- missingRecipient:
when: ${ ($data.recipient // "") == "" }
then: validationFailed
- default:
then: afterValidation
# --- failure path: only reached via a named redirect above -------------
- validationFailed:
set:
errorTitle: Invalid notification.create event
errorDetail: Some details
# `raise` always terminates the current execution path. As it is not
# wrapped in a `try`, the error propagates up and fails the workflow, so
# no flow directive is needed to stop the tasks below from running.
- fault:
raise:
error:
type: https://zigflow.dev/spec/1.0.0/errors/validation
status: 400
title: ${ $data.errorTitle }
detail: ${ $data.errorDetail }
# --- happy path resumes here ------------------------------------------
- afterValidation:
set:
validated: trueI generated this with the Zigflow MCP server - that reads the docs and examples to build things. Hopefully, that will help you too. I think the Authorise Change Request example might be handy for your wider problem area - there are three branches:
I've created two issues from this (#584 and #585). Thank you for raising |
|
Thanks for answer! @mrsimonemms Now it’s clearer to me. I see that when switching to a specific task, a child workflow is created, which is expected, but not quite what I need. anchors:
notificationSendSteps: ¬ificationSendSteps
- initData:
set:
version: "1.0.0"
- handleValidateInputError:
if: ${ $input.payload.ntf_code == "code" }
set:
validationFailed: true
# Here are tasks with a similar check. if: ${ $data.validationFailed }
.....
- afterFault2:
if: ${ $data.validationFailed }
raise:
error:
type: error
status: 400
title: Invalid notification.create event
detail: Some detailsMaybe this will be useful to someone. |
Hi @PavelVydysh, yes this is by design. The
dotasks are designed to be either:The reality is that there is a bit of a rough edge here that the code has to make a couple of assumptions and it does it by going on the order the tasks are presented in, which is what you're seeing. See the code for the how.
In reality, you shouldn't be putting a nested
dotask in a workflow. You can achieve what you want by removing the nesteddo: