Validation fails when transition.NextState is equal to currentState
What happened:
When doing state transitions, whenever the transition.NextState is defined as the currentState, the validation fails with the error Error:Field validation for 'NextState' failed on the 'recursivestate' tag"
What you expected to happen: The validation should not fail when transitioning to the same state.
How to reproduce it: Take for example this state
{
"name": "FineUser",
"type": "operation",
"actions": [
{
"functionRef": {
"refName": "FineUserFn"
}
}
],
"transition": "CallExternalAPI",
"onErrors": [
{
"errorRef": "ServicesNotAvailable",
"transition": "FineUser"
},
{
"errorRef": "DefaultErrorRef",
"transition": "Reject"
}
]
}
The validation here fails for onErrors[0] since it is looking to transition to the state FineUser which seems to be not handled in the SDK.
One more example of this is -
{
"name": "UserActionSignal",
"type": "switch",
"eventConditions": [
{
"eventRef": "fine_user",
"transition": "FineUser"
},
{
"eventRef": "reward_user",
"transition": "RewardUser"
}
],
"metadata": {
"moduleNameTag": "USER_REWARD_INPUT",
"moduleStatusTag": "WAIT"
},
"timeouts": {
"eventTimeout": "PT5S"
},
"defaultCondition": {
"transition": "UserActionSignal"
}
}
here, the default transition is configured as UserActionSignal but since the nextState is same as the currentState, the validator throws the error.
Anything else we need to know?:
Environment:
- SDK version: v2.2.5
- Go version: go1.20.14 darwin/arm64
The validation here fails for onErrors[0] since it is looking to transition to the state FineUser which seems to be not handled in the SDK.
So where's the state FineUser? I can't see it in your excerpt.
here, the default transition is configured as UserActionSignal but since the nextState is same as the currentState, the validator throws the error.
So this will be an infinite loop, it's not valid.
Handling for an infinite loop should be done from the application level. You can think of this as an "indefinite" retry which keeps on triggering this state till a certain result is achieved. Isn't this like just a classic recursion where you supply a base condition. The base condition in this case can be an event received, a signal received, etc. Ideally Go SDK should not be the one making the call to allow/disallow using of infinite loop.
The validation here fails for onErrors[0] since it is looking to transition to the state FineUser which seems to be not handled in the SDK.
So where's the state
FineUser? I can't see it in your excerpt.here, the default transition is configured as UserActionSignal but since the nextState is same as the currentState, the validator throws the error.
So this will be an infinite loop, it's not valid.
On line 1 of example 1, the state is called "FineUser"
@Kshitiz1403 A contribution in this scenario.
In the Monitor Job Example, it has a sleep state, avoiding a loop that can cause many calls, in a very short time for the function.
@Kshitiz1403 I can see an appeal for this use case, which I overlooked yesterday. Feel free to send a PR, this is a valid DSL.
@ribeiromiranda in the case of their switch example, the engine should wait for 5 seconds and then transition again to the beginning of the node waiting for the event to arrive.
I would implement this using callbacks instead. But no matter what, the SDK should allow it.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Closed as stale