From 8c093fdf9f4d48269024641fa5916fe534134ae6 Mon Sep 17 00:00:00 2001 From: Andrew Sisley Date: Fri, 4 Oct 2024 10:34:49 -0400 Subject: [PATCH] WIP - Handle explicit nil sec side rels --- internal/db/collection.go | 4 +++ tests/integration/events.go | 4 +++ .../one_to_one/with_null_value_test.go | 31 ++++++++++++++++--- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/internal/db/collection.go b/internal/db/collection.go index dd1a413946..c68fe99314 100644 --- a/internal/db/collection.go +++ b/internal/db/collection.go @@ -657,6 +657,10 @@ func (c *collection) save( relationFieldDescription, isSecondaryRelationID := fieldDescription.GetSecondaryRelationField(c.Definition()) if isSecondaryRelationID { + if val.Value() == nil { + continue //todo - doc + } + primaryId := val.Value().(string) err = c.patchPrimaryDoc( diff --git a/tests/integration/events.go b/tests/integration/events.go index bf004b99aa..89637bb766 100644 --- a/tests/integration/events.go +++ b/tests/integration/events.go @@ -335,6 +335,10 @@ func getEventsForCreateDoc(s *state, action CreateDoc) map[string]struct{} { // check for any secondary relation fields that could publish an event for f, v := range doc.Values() { + if v.Value() == nil { + continue //todo doc + } + field, ok := def.GetFieldByName(f.Name()) if !ok { continue // ignore unknown field diff --git a/tests/integration/mutation/create/field_kinds/one_to_one/with_null_value_test.go b/tests/integration/mutation/create/field_kinds/one_to_one/with_null_value_test.go index a428f76681..a6421aec5c 100644 --- a/tests/integration/mutation/create/field_kinds/one_to_one/with_null_value_test.go +++ b/tests/integration/mutation/create/field_kinds/one_to_one/with_null_value_test.go @@ -13,8 +13,6 @@ package one_to_one import ( "testing" - "github.com/stretchr/testify/require" - testUtils "github.com/sourcenetwork/defradb/tests/integration" ) @@ -119,10 +117,33 @@ func TestMutationCreateOneToOne_WithExplicitNullOnSecondarySide(t *testing.T) { "published": testUtils.NewDocIndex(0, 0), }, }, + testUtils.Request{ + Request: ` + query { + Book { + name + author { + name + } + } + }`, + Results: map[string]any{ + "Book": []map[string]any{ + { + "name": "Secrets at Maple Syrup Farm", + "author": nil, + }, + { + "name": "How to Be a Canadian", + "author": map[string]any{ + "name": "Will Ferguson", + }, + }, + }, + }, + }, }, } - require.Panics(t, func() { - testUtils.ExecuteTestCase(t, test) - }) + testUtils.ExecuteTestCase(t, test) }