Skip to content

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

Description

@kuishou68

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:

// 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:

// 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

// 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:

// 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")
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions