Skip to content

Commit

Permalink
Return fast before traverse for wrong ids
Browse files Browse the repository at this point in the history
  • Loading branch information
oguzhankoral committed Feb 1, 2025
1 parent 3aa993c commit 23952d2
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Speckle.Sdk/Serialisation/V2/Receive/DeserializeProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,18 @@ public sealed class DeserializeProcess(
[AutoInterfaceIgnore]
public void Dispose() => objectLoader.Dispose();

/// <summary>
/// All meaningful ids in the upcoming version
/// </summary>
private List<Id> AllChildrenIds { get; set; }

public async Task<Base> Deserialize(string rootId)
{
var (rootJson, childrenIds) = await objectLoader
.GetAndCache(rootId, _options, cancellationToken)
.ConfigureAwait(false);
AllChildrenIds = childrenIds.ToList();
AllChildrenIds.Add(new Id(rootId));
Total = childrenIds.Count;
Total++;
var root = new Id(rootId);
Expand All @@ -53,6 +60,13 @@ public async Task<Base> Deserialize(string rootId)

private async Task Traverse(Id id)
{
// It doesn't make sense to try traverse id if it is not in the root, if this is the case object is serialized wrong in the first place.
// This happened with datachunks that having weird __closures
if (!AllChildrenIds.Contains(id))
{
return;
}

if (_baseCache.ContainsKey(id))
{
return;
Expand Down Expand Up @@ -106,6 +120,7 @@ private async Task Traverse(Id id)
if (!_closures.TryGetValue(id, out var closures))
{
var j = objectLoader.LoadId(id.Value);

if (j == null)
{
throw new SpeckleException($"Missing object id in SQLite cache: {id}");
Expand Down

0 comments on commit 23952d2

Please sign in to comment.