From 29be2cca27885322aeedeb44ac4179382e7ac3c1 Mon Sep 17 00:00:00 2001 From: theresa Date: Thu, 26 Aug 2021 16:00:11 +0200 Subject: [PATCH] People: Throw correct error in ReportCollision when embedding is empty #22 --- internal/entity/face.go | 2 +- internal/entity/face_test.go | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/internal/entity/face.go b/internal/entity/face.go index 02f32af24..111429ce0 100644 --- a/internal/entity/face.go +++ b/internal/entity/face.go @@ -148,7 +148,7 @@ func (m *Face) ReportCollision(embeddings Embeddings) (reported bool, err error) if m.SubjectUID == "" { // Ignore reports for anonymous faces. return false, nil - } else if m.ID == "" || len(m.EmbeddingJSON) == 0 { + } else if m.ID == "" { return false, fmt.Errorf("invalid face id") } else if len(m.EmbeddingJSON) == 0 { return false, fmt.Errorf("embedding must not be empty") diff --git a/internal/entity/face_test.go b/internal/entity/face_test.go index b41cfbf21..a61726070 100644 --- a/internal/entity/face_test.go +++ b/internal/entity/face_test.go @@ -102,6 +102,16 @@ func TestFace_ReportCollision(t *testing.T) { assert.Equal(t, "invalid face id", err.Error()) } }) + t.Run("embedding empty", func(t *testing.T) { + m := NewFace("123", SrcAuto, Embeddings{}) + m.EmbeddingJSON = []byte("") + if reported, err := m.ReportCollision(MarkerFixtures.Pointer("1000003-4").Embeddings()); err == nil { + t.Fatal(err) + } else { + assert.False(t, reported) + assert.Equal(t, "embedding must not be empty", err.Error()) + } + }) } func TestFace_ReviseMatches(t *testing.T) {