Skip to content

Commit

Permalink
Handle asset not in dict during update result handling (#460)
Browse files Browse the repository at this point in the history
This happens if only _some_ assets in the update have parents.
  • Loading branch information
einarmo authored Aug 29, 2024
1 parent 0769da8 commit 56c4e74
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
14 changes: 8 additions & 6 deletions Cognite.Extensions/Assets/AssetUpdateResultHandlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public static async Task<IEnumerable<CogniteError<AssetUpdateItem>>> VerifyAsset
hasParent = true;
}


if (hasParent)
{
var idt = item.ExternalId != null ? Identity.Create(item.ExternalId) : Identity.Create(item.Id!.Value);
Expand All @@ -179,7 +179,7 @@ public static async Task<IEnumerable<CogniteError<AssetUpdateItem>>> VerifyAsset
var err = ParseSimpleError(ex, assetsToFetch, items);
return new[] { err };
}

var byId = assets.ToDictionary(asset => asset.Id);
var byExtId = assets.Where(asset => asset.ExternalId != null).ToDictionary(asset => asset.ExternalId);

Expand All @@ -188,9 +188,11 @@ public static async Task<IEnumerable<CogniteError<AssetUpdateItem>>> VerifyAsset

foreach (var item in items)
{
Asset self;
if (item.Id.HasValue) self = byId[item.Id.Value];
else self = byExtId[item.ExternalId];
Asset? self = null;
if (item.Id.HasValue) byId.TryGetValue(item.Id.Value, out self);
else byExtId.TryGetValue(item.ExternalId, out self);

if (self == null) continue;

Asset? parent = null;

Expand All @@ -205,7 +207,7 @@ public static async Task<IEnumerable<CogniteError<AssetUpdateItem>>> VerifyAsset
missingParents.Add((Identity.Create(item.Update.ParentExternalId.Set), item));
continue;
}

// No parentId is set
if (parent == null) continue;

Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.24.3
1.24.4

0 comments on commit 56c4e74

Please sign in to comment.