diff --git a/ci/release/changelogs/next.md b/ci/release/changelogs/next.md index 59bb6569d..acd76b3fc 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 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 76e83ae2c..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(id.(string))] = o + children[strings.ToLower(o.ID)] = o o.Parent = idToObj[so["AbsID"].(string)] } diff --git a/d2graph/serde_test.go b/d2graph/serde_test.go index 070400f20..9d52b91f7 100644 --- a/d2graph/serde_test.go +++ b/d2graph/serde_test.go @@ -17,19 +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, - ) + assert.Contains(t, a.Children, "a") + 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)