From d1efedca9a2a6a6d03d34ab637308a0c0bd99c1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BAlio=20C=C3=A9sar=20Batista?= Date: Fri, 17 Feb 2023 15:35:13 -0300 Subject: [PATCH 1/4] fix deserialization of obj.children --- d2graph/serde.go | 3 +-- d2graph/serde_test.go | 6 ++++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/d2graph/serde.go b/d2graph/serde.go index 76e83ae2c..638e2bc82 100644 --- a/d2graph/serde.go +++ b/d2graph/serde.go @@ -2,7 +2,6 @@ package d2graph import ( "encoding/json" - "strings" "oss.terrastruct.com/util-go/go2" ) @@ -49,7 +48,7 @@ func DeserializeGraph(bytes []byte, g *Graph) error { for _, id := range so["ChildrenArray"].([]interface{}) { o := idToObj[id.(string)] childrenArray = append(childrenArray, o) - children[strings.ToLower(id.(string))] = o + children[o.IDVal] = o o.Parent = idToObj[so["AbsID"].(string)] } diff --git a/d2graph/serde_test.go b/d2graph/serde_test.go index 070400f20..e882c8fba 100644 --- a/d2graph/serde_test.go +++ b/d2graph/serde_test.go @@ -31,6 +31,12 @@ func TestSerialization(t *testing.T) { g.Root.ChildrenArray[0].Parent, ) + a := g.Root.ChildrenArray[0] + aa := a.ChildrenArray[0] + assert.Contains(t, a.Children, "a") + assert.Contains(t, aa.Children, "b") + assert.Contains(t, aa.Children, "c") + assert.Equal(t, 1, len(g.Edges)) assert.Equal(t, "b", g.Edges[0].Src.ID) assert.Equal(t, "c", g.Edges[0].Dst.ID) From b2394184cbb41215d7a338a05a6a07dd76c4fff8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BAlio=20C=C3=A9sar=20Batista?= Date: Fri, 17 Feb 2023 15:39:40 -0300 Subject: [PATCH 2/4] chagelog --- ci/release/changelogs/next.md | 1 + 1 file changed, 1 insertion(+) diff --git a/ci/release/changelogs/next.md b/ci/release/changelogs/next.md index 59bb6569d..46f11dc1c 100644 --- a/ci/release/changelogs/next.md +++ b/ci/release/changelogs/next.md @@ -13,3 +13,4 @@ - Fixes rare compiler bug when using underscores in edges to create objects across containers. [#824](https://github.com/terrastruct/d2/pull/824) - Fixes rare possibility of rendered connections being hidden or cut off. [#828](https://github.com/terrastruct/d2/pull/828) - Creating nested children within `sql_table` and `class` shapes are now prevented (caused confusion when accidentally done). [#834](https://github.com/terrastruct/d2/pull/834) +- Fixes graph deserialization. [#837](https://github.com/terrastruct/d2/pull/837) \ No newline at end of file From a6533067ec5af990d1477074ff691defeebf1f8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BAlio=20C=C3=A9sar=20Batista?= Date: Fri, 17 Feb 2023 15:44:33 -0300 Subject: [PATCH 3/4] fix test --- d2graph/serde.go | 3 ++- d2graph/serde_test.go | 24 +++++++++--------------- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/d2graph/serde.go b/d2graph/serde.go index 638e2bc82..6b46a2697 100644 --- a/d2graph/serde.go +++ b/d2graph/serde.go @@ -2,6 +2,7 @@ package d2graph import ( "encoding/json" + "strings" "oss.terrastruct.com/util-go/go2" ) @@ -48,7 +49,7 @@ func DeserializeGraph(bytes []byte, g *Graph) error { for _, id := range so["ChildrenArray"].([]interface{}) { o := idToObj[id.(string)] childrenArray = append(childrenArray, o) - children[o.IDVal] = o + children[strings.ToLower(o.IDVal)] = o o.Parent = idToObj[so["AbsID"].(string)] } diff --git a/d2graph/serde_test.go b/d2graph/serde_test.go index e882c8fba..9d52b91f7 100644 --- a/d2graph/serde_test.go +++ b/d2graph/serde_test.go @@ -17,25 +17,19 @@ func TestSerialization(t *testing.T) { assert.Nil(t, err) asserts := func(g *d2graph.Graph) { + a := g.Root.ChildrenArray[0] + a_a := a.ChildrenArray[0] + assert.Equal(t, 4, len(g.Objects)) assert.Equal(t, 1, len(g.Root.ChildrenArray)) - assert.Equal(t, 1, len(g.Root.ChildrenArray[0].ChildrenArray)) - assert.Equal(t, 2, len(g.Root.ChildrenArray[0].ChildrenArray[0].ChildrenArray)) - assert.Equal(t, - g.Root.ChildrenArray[0], - g.Root.ChildrenArray[0].ChildrenArray[0].Parent, - ) + assert.Equal(t, 1, len(a.ChildrenArray)) + assert.Equal(t, 2, len(a_a.ChildrenArray)) + assert.Equal(t, a, a_a.Parent) + assert.Equal(t, g.Root, a.Parent) - assert.Equal(t, - g.Root, - g.Root.ChildrenArray[0].Parent, - ) - - a := g.Root.ChildrenArray[0] - aa := a.ChildrenArray[0] assert.Contains(t, a.Children, "a") - assert.Contains(t, aa.Children, "b") - assert.Contains(t, aa.Children, "c") + assert.Contains(t, a_a.Children, "b") + assert.Contains(t, a_a.Children, "c") assert.Equal(t, 1, len(g.Edges)) assert.Equal(t, "b", g.Edges[0].Src.ID) From 1df56853b5c1cabe2c37e712ac6c3da56aded01d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BAlio=20C=C3=A9sar=20Batista?= Date: Fri, 17 Feb 2023 15:54:02 -0300 Subject: [PATCH 4/4] pr comment --- ci/release/changelogs/next.md | 2 +- d2graph/serde.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/release/changelogs/next.md b/ci/release/changelogs/next.md index 46f11dc1c..acd76b3fc 100644 --- a/ci/release/changelogs/next.md +++ b/ci/release/changelogs/next.md @@ -13,4 +13,4 @@ - Fixes rare compiler bug when using underscores in edges to create objects across containers. [#824](https://github.com/terrastruct/d2/pull/824) - Fixes rare possibility of rendered connections being hidden or cut off. [#828](https://github.com/terrastruct/d2/pull/828) - Creating nested children within `sql_table` and `class` shapes are now prevented (caused confusion when accidentally done). [#834](https://github.com/terrastruct/d2/pull/834) -- Fixes graph deserialization. [#837](https://github.com/terrastruct/d2/pull/837) \ No newline at end of file +- Fixes graph deserialization bug. [#837](https://github.com/terrastruct/d2/pull/837) \ No newline at end of file diff --git a/d2graph/serde.go b/d2graph/serde.go index 6b46a2697..1e1778577 100644 --- a/d2graph/serde.go +++ b/d2graph/serde.go @@ -49,7 +49,7 @@ func DeserializeGraph(bytes []byte, g *Graph) error { for _, id := range so["ChildrenArray"].([]interface{}) { o := idToObj[id.(string)] childrenArray = append(childrenArray, o) - children[strings.ToLower(o.IDVal)] = o + children[strings.ToLower(o.ID)] = o o.Parent = idToObj[so["AbsID"].(string)] }