Skip to content

Commit

Permalink
Fix cleaning of missing parentExternalId requests (#409)
Browse files Browse the repository at this point in the history
* Fix cleaning of missing parentExternalId requests

We need to exclude assets included in the request when doing this.

* Bump version
  • Loading branch information
einarmo authored May 2, 2024
1 parent 0522d2b commit 18b8c13
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
8 changes: 7 additions & 1 deletion Cognite.Extensions/Assets/AssetResultHandlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,17 @@ public static async Task CompleteAssetError(

if (error.Resource == ResourceType.ParentExternalId)
{
// Retrieve all parents, unless they are already checked (i.e. retrieved from the initial request),
// or if they are included in the request itself.
var ids = assets.Select(asset => asset.ParentExternalId)
.Where(id => id != null)
.Distinct()
.Select(Identity.Create)
.Except(error.Values ?? Enumerable.Empty<Identity>());
.Except(error.Values ?? Enumerable.Empty<Identity>())
.Except(assets
.Where(asset => asset.ExternalId != null)
.Select(asset => Identity.Create(asset.ExternalId))
);

if (!ids.Any())
{
Expand Down
25 changes: 17 additions & 8 deletions ExtractorUtils.Test/integration/AssetIntegrationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ await tester.Destination.CogniteClient.Assets.DeleteAsync(new AssetDelete
public async Task TestSanitation(CogniteHost host)
{
using var tester = new CDFTester(host, _output);

var assets = new[] {
new AssetCreate
{
Expand Down Expand Up @@ -176,7 +176,7 @@ await tester.Destination.CogniteClient.Assets.DeleteAsync(new AssetDelete
}, tester.Source.Token);
}
}

[Theory]
[InlineData(CogniteHost.GreenField)]
[InlineData(CogniteHost.BlueField)]
Expand Down Expand Up @@ -262,6 +262,11 @@ await tester.Destination.EnsureAssetsExistsAsync(new[]
{
Name = "final-asset-ok",
ExternalId = $"{tester.Prefix} final-asset-ok"
},
new AssetCreate {
Name = "asset-ok-local-parent",
ExternalId = $"{tester.Prefix} asset-ok-local-parent",
ParentExternalId = $"{tester.Prefix} final-asset-ok"
}
};
try
Expand All @@ -270,7 +275,7 @@ await tester.Destination.EnsureAssetsExistsAsync(new[]

tester.Logger.LogResult(result, RequestType.CreateAssets, false);

Assert.Single(result.Results);
Assert.Equal(2, result.Results.Count());
Assert.Equal(6, result.Errors.Count());
Assert.Equal("final-asset-ok", result.Results.First().Name);
foreach (var error in result.Errors)
Expand Down Expand Up @@ -334,7 +339,8 @@ await tester.Destination.EnsureAssetsExistsAsync(new[]
$"{tester.Prefix} test-missing-dataset",
$"{tester.Prefix} test-missing-dataset-2",
$"{tester.Prefix} final-asset-ok",
$"{tester.Prefix} test-null-metadata"
$"{tester.Prefix} test-null-metadata",
$"{tester.Prefix} asset-ok-local-parent"
};
await tester.Destination.CogniteClient.Assets.DeleteAsync(new AssetDelete
{
Expand Down Expand Up @@ -500,7 +506,7 @@ public async Task TestUpdateErrorHandling(CogniteHost host)
new AssetUpdateItem(assets[1].ExternalId)
{
Update = new AssetUpdate
{
{
Description = new UpdateNullable<string>("New description")
}
},
Expand Down Expand Up @@ -736,14 +742,16 @@ public async Task TestUpsert(bool replaceMeta)
result2.Throw();
Assert.Equal(5, result3.Results.Count());
result3.Throw();
Assert.All(result3.Results, res => {
Assert.All(result3.Results, res =>
{
Assert.Single(res.Metadata);
Assert.Equal("someValue", res.Metadata["someKey"]);
Assert.Equal("Some description", res.Description);
});
Assert.Equal(7, result4.Results.Count());
result4.Throw();
Assert.All(result4.Results.Take(5), res => {
Assert.All(result4.Results.Take(5), res =>
{
if (replaceMeta)
{
Assert.Single(res.Metadata);
Expand All @@ -759,7 +767,8 @@ public async Task TestUpsert(bool replaceMeta)
Assert.Equal(7, result5.Results.Count());
Assert.Single(result5.Errors);
Assert.Equal(2, result5.Errors.First().Skipped.Count());
Assert.All(result5.Results, res => {
Assert.All(result5.Results, res =>
{
Assert.Equal("Some source", res.Source);
});
}
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.22.0
1.22.1

0 comments on commit 18b8c13

Please sign in to comment.