[Bug]: Go metadata selector crashes on non-string document IDs

#20537 · closed · 1 comments

View on GitHub ↗

Harsh23Kashyap

The Go metadata batch handler accepts JSON into a map, then `parseMetadataSelector` converts each `selector.document_ids` item with `id.(string)` without checking its type. A numeric item causes a panic instead of a validation error. This parser is shared by `POST /api/v1/datasets/{id}/metadata/update` and `PATCH /api/v1/datasets/{id}/documents/metadatas`. The documented field type is `list[string]`. Minimal parser input: ```json {"selector":{"document_ids":[123]}} ``` Observed output: ```text PANIC: interface conversion: interface {} is float64, not string ``` Expected: reject non-string IDs with a data error, consistent with the existing `document_ids must be a list.` validation. Checked on main at `98b48a085786fb9e14be8753b5a9a9ea02230ccf`. A standalone harness copied `parseMetadataSelector` verbatim, used a local `MetadataSelector` type stub, and decoded the input with `encoding/json`. Two runs produced identical output. String IDs succeeded; a non-list value returned the existing validation message. Full handler tests could not complete because compiling the Elasticsearch dependency exceeded local memory. I have not verified an HTTP response from a running server.

Comments

Harsh23Kashyap

I'd like to work on this. I'll open a PR shortly.