Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix deserialization issue with null workspace refs #13423

Merged
merged 1 commit into from
Oct 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/DynamoCore/Graph/Workspaces/SerializationConverters.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
Expand Down Expand Up @@ -604,6 +604,11 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
if (obj[NodeLibraryDependenciesPropString] != null)
{
workspaceReferences = obj[NodeLibraryDependenciesPropString].ToObject<IEnumerable<INodeLibraryDependencyInfo>>(serializer);
//if deserialization failed, reset to empty.
if (workspaceReferences == null)
{
workspaceReferences = new List<INodeLibraryDependencyInfo>();
}
}
else
{
Expand Down
23 changes: 22 additions & 1 deletion test/DynamoCoreTests/SerializationTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
Expand Down Expand Up @@ -650,6 +650,27 @@ public void ConverterDoesNotThrowWithNullEngine()
CurrentDynamoModel.AddHomeWorkspace();
Assert.DoesNotThrow(() => { CurrentDynamoModel.CurrentWorkspace.ToJson(null); });
}
[Test]
public void NullWorkspaceRefsDeserializedAsEmpty()
{

var testFile = Path.Combine(TestDirectory, @"core\serialization\nullWorkspaceRefs.dyn");
var json = File.ReadAllText(testFile);

Assert.DoesNotThrow(() =>
{
var ws = WorkspaceModel.FromJson(
json, this.CurrentDynamoModel.LibraryServices,
null,
null,
this.CurrentDynamoModel.NodeFactory,
true,
true,
this.CurrentDynamoModel.CustomNodeManager);

Assert.NotNull(ws);
});
}

[Test]
public void ReadConverterDoesNotThrowWithNullEngineAndScheduler()
Expand Down
61 changes: 61 additions & 0 deletions test/core/serialization/nullWorkspaceRefs.dyn
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"Uuid": "077eb433-543f-4cc7-bc2a-91fcaea5687e",
"IsCustomNode": false,
"Description": "",
"Name": "broken",
"ElementResolver": {
"ResolutionMap": {}
},
"Inputs": [],
"Outputs": [],
"Nodes": [],
"Connectors": [],
"Dependencies": [],
"NodeLibraryDependencies": null,
"Thumbnail": "",
"GraphDocumentationURL": null,
"ExtensionWorkspaceData": [
{
"ExtensionGuid": "28992e1d-abb9-417f-8b1b-05e053bee670",
"Name": "Properties",
"Version": "2.16",
"Data": {}
}
],
"Author": "",
"Linting": {
"activeLinter": "None",
"activeLinterId": "7b75fb44-43fd-4631-a878-29f4d5d8399a",
"warningCount": 0,
"errorCount": 0
},
"Bindings": [],
"View": {
"Dynamo": {
"ScaleFactor": 1.0,
"HasRunWithoutCrash": true,
"IsVisibleInDynamoLibrary": true,
"Version": "2.16.0.1926",
"RunType": "Automatic",
"RunPeriod": "1000"
},
"Camera": {
"Name": "Background Preview",
"EyeX": -17.0,
"EyeY": 24.0,
"EyeZ": 50.0,
"LookX": 12.0,
"LookY": -13.0,
"LookZ": -58.0,
"UpX": 0.0,
"UpY": 1.0,
"UpZ": 0.0
},
"ConnectorPins": [],
"NodeViews": [],
"Annotations": [],
"X": 0.0,
"Y": 0.0,
"Zoom": 1.0
}
}