Skip to content

Commit 78b1747

Browse files
authored
Merge branch 'develop' into combined-bot-prs-branch
2 parents 0f23a08 + 2fd9e2b commit 78b1747

4 files changed

Lines changed: 32 additions & 3 deletions

File tree

cbindings/node_close.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ func CloseNode(nodePtr C.uintptr_t) C.Result {
2727
if err != nil {
2828
return returnC(returnGoC(1, err.Error(), ""))
2929
}
30-
err = node.Close(context.Background())
31-
if err != nil {
30+
defer cgo.Handle(nodePtr).Delete()
31+
32+
if err := node.Close(context.Background()); err != nil {
3233
return returnC(GoCResult{1, err.Error(), ""})
3334
}
34-
cgo.Handle(nodePtr).Delete()
3535
return returnC(GoCResult{0, "", ""})
3636
}

internal/request/graphql/parser/errors.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,5 @@ var (
2828
ErrInvalidFilterConditions = errors.New("invalid filter condition type, expected map")
2929
ErrMultipleOrderFieldsDefined = errors.New("each order argument can only define one field")
3030
ErrMultipleDocIDsNotSupported = errors.New("querying by multiple docIDs is not yet supported")
31+
ErrSimilarityMissingTarget = errors.New("similarity requires a target field argument")
3132
)

internal/request/graphql/parser/query.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,11 @@ func parseSimilarity(
250250
v := arguments[target].(map[string]any)
251251
vector = v[types.SimilarityArgVector]
252252
}
253+
// The argument names the field to compare against, so without one there is nothing to
254+
// compare. The mapper looks the target up by name and would panic on the empty name.
255+
if target == "" {
256+
return nil, ErrSimilarityMissingTarget
257+
}
253258

254259
return &request.Similarity{
255260
Field: request.Field{

tests/integration/query/simple/with_similarity_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,3 +517,26 @@ func TestQuerySimple_WithTwoSimilarityAndFilteringOnBoth_ShouldSucceed(t *testin
517517

518518
testUtils.ExecuteTestCase(t, test)
519519
}
520+
521+
func TestQuerySimple_WithSimilarityAndNoArguments_ShouldError(t *testing.T) {
522+
test := testUtils.TestCase{
523+
Actions: []any{
524+
&action.AddCollection{
525+
SDL: `type User {
526+
name: String
527+
vector: [Int!]
528+
}`,
529+
},
530+
&action.Request{
531+
Request: `query {
532+
User {
533+
SIMILARITY
534+
}
535+
}`,
536+
ExpectedError: "similarity requires a target field argument",
537+
},
538+
},
539+
}
540+
541+
testUtils.ExecuteTestCase(t, test)
542+
}

0 commit comments

Comments
 (0)