Skip to content

Commit 76afb96

Browse files
authored
Update sub-orchestration default versioning (#437)
This commit updates the sub-orchestration default version handling to incorporate properties from TaskOrchestrationContext. These properties are generated and passed into the context by systems using Durable Functions. Signed-off-by: halspang <[email protected]>
1 parent 915b4c3 commit 76afb96

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

src/Abstractions/TaskOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public SubOrchestrationOptions(TaskOptions options, string? instanceId = null)
9494
/// <summary>
9595
/// Gets the version to associate with the sub-orchestration instance.
9696
/// </summary>
97-
public TaskVersion Version { get; init; } = default!;
97+
public TaskVersion? Version { get; init; }
9898
}
9999

100100
/// <summary>

src/Client/Grpc/GrpcDurableTaskClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public override async Task<string> ScheduleNewOrchestrationInstanceAsync(
7979
Check.NotEntity(this.options.EnableEntitySupport, options?.InstanceId);
8080

8181
// We're explicitly OK with an empty version from the options as that had to be explicitly set. It should take precedence over the default.
82-
string version = string.Empty;
82+
string? version = null;
8383
if (options?.Version is { } v)
8484
{
8585
version = v;

src/Worker/Core/Shims/TaskOrchestrationContextWrapper.cs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,8 @@ public override async Task<TResult> CallSubOrchestratorAsync<TResult>(
179179
static string? GetInstanceId(TaskOptions? options)
180180
=> options is SubOrchestrationOptions derived ? derived.InstanceId : null;
181181
string instanceId = GetInstanceId(options) ?? this.NewGuid().ToString("N");
182-
string defaultVersion = this.invocationContext.Options?.Versioning?.DefaultVersion ?? string.Empty;
183-
string version = options is SubOrchestrationOptions subOptions ? subOptions.Version : defaultVersion;
184-
182+
string defaultVersion = this.GetDefaultVersion();
183+
string version = options is SubOrchestrationOptions { Version: { } v } ? v.Version : defaultVersion;
185184
Check.NotEntity(this.invocationContext.Options.EnableEntitySupport, instanceId);
186185

187186
// if this orchestration uses entities, first validate that the suborchestration call is allowed in the current context
@@ -482,4 +481,22 @@ async Task<T> InvokeWithCustomRetryHandler<T>(
482481
}
483482
}
484483
}
484+
485+
// The default version can come from two different places depending on the context of the invocation.
486+
string GetDefaultVersion()
487+
{
488+
// Preferred choice.
489+
if (this.invocationContext.Options.Versioning?.DefaultVersion is { } v)
490+
{
491+
return v;
492+
}
493+
494+
// Secondary choice.
495+
if (this.Properties.TryGetValue("defaultVersion", out var propVersion) && propVersion is string v2)
496+
{
497+
return v2;
498+
}
499+
500+
return string.Empty;
501+
}
485502
}

0 commit comments

Comments
 (0)