Skip to content

Commit 1d96642

Browse files
authored
Fix handling of mismatched datapoints against CDM (#630)
This was causing issues, because the code assumed that if there was no identity with `Id` in the datapoints request, it must be there using `ExternalId`. Now that we can use `InstanceId` instead, that was no longer correct. I've fixed the issue, and also made it so that we throw an explicit exception if this should ever happen again. There's an implicit ordering here. _Technically_ a caller could reference a timeseries in multiple ways in the same request, but I think it's fair to call that outside of what we want to support. None of our extractors currently do this, and I think it would fail against the timeseries API at another time.
1 parent 40fa916 commit 1d96642

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

Cognite.Extensions/TimeSeries/DataPointResultHandlers.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,19 @@ public static IDictionary<Identity, IEnumerable<Datapoint>> CleanFromError(
137137

138138
foreach (var ts in timeseries)
139139
{
140-
var idt = datapoints.ContainsKey(Identity.Create(ts.Id)) ? Identity.Create(ts.Id) : Identity.Create(ts.ExternalId);
140+
Identity idt;
141+
if (datapoints.ContainsKey(Identity.Create(ts.Id))) idt = Identity.Create(ts.Id);
142+
else if (ts.InstanceId != null && datapoints.ContainsKey(Identity.Create(ts.InstanceId))) idt = Identity.Create(ts.InstanceId);
143+
else if (ts.ExternalId != null && datapoints.ContainsKey(Identity.Create(ts.ExternalId))) idt = Identity.Create(ts.ExternalId);
144+
else
145+
{
146+
// This should not happen, and would indicate a bug in CDF itself, or some future
147+
// change to the timeseries API that would make this possible. Throw an explicit exception,
148+
// there is no safe recovery possible here, since we don't have a way to communicate to the caller
149+
// to remove this timeseries, since we don't know how to identify it in the original request.
150+
throw new InvalidOperationException($"Retrieved timeseries {ts.Id} which was not requested");
151+
}
152+
141153
var points = datapoints[idt];
142154

143155
var bad = new List<Datapoint>();

version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.39.0
1+
1.39.1

0 commit comments

Comments
 (0)