I’m facing an issue related to workflow versioning in Temporal and need some clarification.I introduced a new activity inside a versioned block like this:
v := workflow.GetVersion(ctx, “MyChangeID”, workflow.DefaultVersion, 2)
if v >= 2 {
// Newly added activity
var result MyResult
err := workflow.ExecuteActivity(ctx, MyNewActivity, input).Get(ctx, &result)
if err != nil {
return err
}
}
I forgot to register MyNewActivity in the worker.
However, I expected that already-running workflows (created before introducing version 2) would continue on the old codepath and not attempt to execute this new activity.
But instead, I got this error during replay of an existing workflow: ActivityNotRegisteredError: activityType=MyNewActivity
Why would a running workflow attempt to execute a newly introduced activity within a versioned block?
Under what conditions does GetVersion not protect against this?
The GetVersion condition is evaluated when it is called. So if the workflow didn’t reach that code it will take the new code path even if workflow started before the change was introduced. This is actually a feature, not a bug as it allows fixing bugs in already running workflows.
If you don’t want this behavior call GetVersion at the beginning of the workflow execution with the same changeID.
Thanks, that makes sense.
Just two quick clarifications:
So for long-running workflows, if the code inside the versioned block hasn’t executed yet (e.g., workflow was sleeping), it will always take the new version once it reaches that line — even if it started before the change, right?
Is there any official doc , design notes or best-practice guide that explains this behavior in-depth? Especially around:
when to call GetVersion early in the workflow,
patterns for ensuring backward compatibility,
pitfalls when adding new activities or child workflows.