Skip to content
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
3 changes: 3 additions & 0 deletions internal/fields/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,9 @@ func (v *Validator) parseSingleElementValue(key string, definition FieldDefiniti
break
}
return forEachElementValue(key, definition, val, doc, v.parseSingleElementValue)
case nil:
// The document contains a null, let's consider this like an empty array.
return nil
default:
return fmt.Errorf("field %q is a group of fields, it cannot store values", key)
}
Expand Down
15 changes: 15 additions & 0 deletions internal/fields/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,21 @@ func Test_parseElementValue(t *testing.T) {
}
},
},
{
key: "null_array",
value: nil,
definition: FieldDefinition{
Name: "null_array",
Type: "group",
Fields: []FieldDefinition{
{
Name: "id",
Type: "keyword",
},
},
Comment on lines +745 to +750
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be an empty array ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An empty array would work. The problem solved here is when a field defined as group or nested is null in a document, like onepassword.details here elastic/integrations@09a01f2#diff-76a51622c000706ccf925266e2e1255f954f7b55380135342a9d51aa3b81b5cdL55

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I misunderstood the definition field. I thought it was resulting definition built.

Just to be sure, it's being compared the value nil of a field null_array against that definition/schema in definition. Would that be right?

Copy link
Member Author

@jsoriano jsoriano Oct 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this would be like validating a document with this JSON content:

{
  "null_array": null
}

With this fields definition:

- name: null_array
  type: group
  fields: ...

Validation fails without this change.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

},
specVersion: *semver3_0_1,
},
} {

t.Run(test.key, func(t *testing.T) {
Expand Down