Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Abstractions/TaskOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public SubOrchestrationOptions(TaskOptions options, string? instanceId = null)
/// <summary>
/// Gets the version to associate with the sub-orchestration instance.
/// </summary>
public TaskVersion Version { get; init; } = default!;
public TaskVersion? Version { get; init; }
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Client/Grpc/GrpcDurableTaskClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
Check.NotEntity(this.options.EnableEntitySupport, options?.InstanceId);

// 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.
string version = string.Empty;
string? version = null;
if (options?.Version is { } v)
{
version = v;
Expand Down Expand Up @@ -108,7 +108,7 @@

if (Activity.Current?.Id != null || Activity.Current?.TraceStateString != null)
{
if (request.ParentTraceContext == null)

Check warning on line 111 in src/Client/Grpc/GrpcDurableTaskClient.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

Check warning on line 111 in src/Client/Grpc/GrpcDurableTaskClient.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Dereference of a possibly null reference.
{
request.ParentTraceContext = new P.TraceContext();
}
Expand Down
23 changes: 20 additions & 3 deletions src/Worker/Core/Shims/TaskOrchestrationContextWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,8 @@ public override async Task<TResult> CallSubOrchestratorAsync<TResult>(
static string? GetInstanceId(TaskOptions? options)
=> options is SubOrchestrationOptions derived ? derived.InstanceId : null;
string instanceId = GetInstanceId(options) ?? this.NewGuid().ToString("N");
string defaultVersion = this.invocationContext.Options?.Versioning?.DefaultVersion ?? string.Empty;
string version = options is SubOrchestrationOptions subOptions ? subOptions.Version : defaultVersion;

string defaultVersion = this.GetDefaultVersion();
string version = options is SubOrchestrationOptions { Version: { } v } ? v.Version : defaultVersion;
Check.NotEntity(this.invocationContext.Options.EnableEntitySupport, instanceId);

// if this orchestration uses entities, first validate that the suborchestration call is allowed in the current context
Expand Down Expand Up @@ -482,4 +481,22 @@ async Task<T> InvokeWithCustomRetryHandler<T>(
}
}
}

// The default version can come from two different places depending on the context of the invocation.
string GetDefaultVersion()
{
// Preferred choice.
if (this.invocationContext.Options.Versioning?.DefaultVersion is { } v)
{
return v;
}

// Secondary choice.
if (this.Properties.TryGetValue("defaultVersion", out var propVersion) && propVersion is string v2)
{
return v2;
}

return string.Empty;
}
}
Loading