From 8c52b67752245cd9e2ed2ee06be7a5b28d0055c4 Mon Sep 17 00:00:00 2001 From: Michael Kirschner Date: Tue, 25 Oct 2022 12:00:00 -0400 Subject: [PATCH] fix bug (#13423) add test --- .../Workspaces/SerializationConverters.cs | 7 ++- test/DynamoCoreTests/SerializationTests.cs | 23 ++++++- test/core/serialization/nullWorkspaceRefs.dyn | 61 +++++++++++++++++++ 3 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 test/core/serialization/nullWorkspaceRefs.dyn diff --git a/src/DynamoCore/Graph/Workspaces/SerializationConverters.cs b/src/DynamoCore/Graph/Workspaces/SerializationConverters.cs index 47fd8463887..8f82282bca5 100644 --- a/src/DynamoCore/Graph/Workspaces/SerializationConverters.cs +++ b/src/DynamoCore/Graph/Workspaces/SerializationConverters.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; @@ -604,6 +604,11 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist if (obj[NodeLibraryDependenciesPropString] != null) { workspaceReferences = obj[NodeLibraryDependenciesPropString].ToObject>(serializer); + //if deserialization failed, reset to empty. + if (workspaceReferences == null) + { + workspaceReferences = new List(); + } } else { diff --git a/test/DynamoCoreTests/SerializationTests.cs b/test/DynamoCoreTests/SerializationTests.cs index c9ef74cf713..5758f6ad944 100644 --- a/test/DynamoCoreTests/SerializationTests.cs +++ b/test/DynamoCoreTests/SerializationTests.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Globalization; using System.IO; @@ -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() diff --git a/test/core/serialization/nullWorkspaceRefs.dyn b/test/core/serialization/nullWorkspaceRefs.dyn new file mode 100644 index 00000000000..14c1baebf73 --- /dev/null +++ b/test/core/serialization/nullWorkspaceRefs.dyn @@ -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 + } +} \ No newline at end of file