Skip to content

Commit b952cd0

Browse files
committed
Update sub-orchestration default versioning
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 b952cd0

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-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: 30 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,32 @@ async Task<T> InvokeWithCustomRetryHandler<T>(
482481
}
483482
}
484483
}
484+
485+
string GetDefaultVersion()
486+
{
487+
// The default version can come from two different places depending on the context of the invocation.
488+
string? propertiesDefault;
489+
string? optionsDefault;
490+
491+
if (this.invocationContext.Options.Versioning?.DefaultVersion is { } v)
492+
{
493+
optionsDefault = v;
494+
}
495+
else
496+
{
497+
optionsDefault = null;
498+
}
499+
500+
if (this.Properties.TryGetValue("defaultVersion", out var propVersion) && propVersion is string v2)
501+
{
502+
propertiesDefault = v2;
503+
}
504+
else
505+
{
506+
propertiesDefault = null;
507+
}
508+
509+
// Prefer the options default, if both are null there was no provided default version.
510+
return optionsDefault ?? propertiesDefault ?? string.Empty;
511+
}
485512
}

0 commit comments

Comments
 (0)