cloudwego / cloudwego/eino

bug: missing validation for empty ParentIDKey in flow/indexer/parent and flow/retriever/parent

Open
#952 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
13k
Forks
1.1k
Avg merge
4h 6m
Merged PRs (30d)
41

Description

## Problem

The `NewIndexer` function in `flow/indexer/parent/parent.go` and the `NewRetriever` function in `flow/retriever/parent/parent.go` both fail to validate that `Config.ParentIDKey` is non-empty.

If a caller provides an empty `ParentIDKey` (either by omission or mistake), the code silently stores the parent document ID under the empty string key `""` in each sub-document's metadata:

```go
// flow/indexer/parent/parent.go – Store()
subDoc.MetaData[p.parentIDKey] = subDoc.ID // stores under "" when parentIDKey is empty
```

The retriever then attempts to look up the parent ID using the same empty key:

```go
// flow/retriever/parent/parent.go – Retrieve()
if k, ok := subDoc.MetaData[p.parentIDKey]; ok {
```

This silently produces wrong behaviour: the metadata entry ends up filed under `""` rather than a meaningful key, so the parent-child relationship is essentially lost for any caller that inspects metadata with a real key name.

The existing `NewIndexer` already validates the three other required fields (`Indexer`, `Transformer`, `SubIDGenerator`), but the equally critical `ParentIDKey` is left unchecked.

## Steps to Reproduce

```go
// No error is returned – ParentIDKey silently defaults to ""
idx, err := parent.NewIndexer(ctx, &parent.Config{
Indexer: myIndexer,
Transformer: mySplitter,
SubIDGenerator: myGenerator,
// ParentIDKey intentionally omitted
})
// err == nil, but all sub-documents will have metadata[""]=parentID
```

## Expected Behavior

`NewIndexer` and `NewRetriever` should return a descriptive error when `ParentIDKey` is empty, consistent with how the other required fields are validated.

## Fix

Add a validation guard in both constructors:

```go
// flow/indexer/parent/parent.go
if config.ParentIDKey == "" {
return nil, fmt.Errorf("parentIDKey is empty")
}

// flow/retriever/parent/parent.go
if config.ParentIDKey == "" {
return nil, fmt.Errorf("parentIDKey is empty")
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.