Skip to content

Commit

Permalink
Fix the set routine
Browse files Browse the repository at this point in the history
  • Loading branch information
johnml1135 committed Dec 12, 2024
1 parent ff00cb5 commit cae9984
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
18 changes: 17 additions & 1 deletion src/DataAccess/src/SIL.DataAccess/MemoryUpdateBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,23 @@ TField value
(IEnumerable<object> owners, PropertyInfo? prop, object? index) = GetFieldOwners(entity, filter, field);
object[]? indices = index == null ? null : [index];
foreach (object owner in owners)
prop.SetValue(owner, value, indices);
{
if (owner is IDictionary dictionary)
{
if (index != null)
{
dictionary[index] = value;
}
else
{
throw new ArgumentException("Cannot set a field on a dictionary without an index.", nameof(field));
}
}
else
{
prop.SetValue(owner, value, indices);
}
}
}

private static bool IsAnyMethod(MethodInfo mi)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,22 +270,14 @@ public override async Task<Empty> UpdateBuildExecutionData(
ServerCallContext context
)
{
var build = await _builds.GetAsync(request.BuildId, cancellationToken: context.CancellationToken);
if (build == null)
{
throw new RpcException(new Status(StatusCode.NotFound, "Build not found."));
}

var updatedExecutionData = new Dictionary<string, string>(build.ExecutionData);

foreach (var entry in request.ExecutionData)
{
updatedExecutionData[entry.Key] = entry.Value;
}

await _builds.UpdateAsync(
b => b.Id == request.BuildId,
u => u.Set(b => b.ExecutionData, updatedExecutionData),
u =>
{
// initialize ExecutionData if it's null
foreach (KeyValuePair<string, string> entry in request.ExecutionData)
u.Set(b => b.ExecutionData[entry.Key], entry.Value);
},
cancellationToken: context.CancellationToken
);

Expand Down

0 comments on commit cae9984

Please sign in to comment.