{"record":{"id":"dce8a9a522f655f6","repo":"Tencent/WeKnora","slug":"invalid-logical-condition-value-type","errorCode":null,"errorMessage":"invalid logical condition value type","messagePattern":"invalid logical condition value type","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/application/repository/retriever/milvus/filter.go","lineNumber":105,"sourceCode":"\t}\n\n\tparamName := c.convertParamName(cond.Field, counter)\n\treturn &convertResult{\n\t\texprStr: fmt.Sprintf(\"%s %s {%s}\", condField, operator, paramName),\n\t\tparams:  map[string]any{paramName: cond.Value},\n\t}, nil\n}\n\nfunc (c *filter) convertLogicalCondition(\n\tcond *universalFilterCondition,\n\tcounter *int,\n) (*convertResult, error) {\n\tif cond.Value == nil {\n\t\treturn nil, fmt.Errorf(\"milvus filter condition is nil\")\n\t}\n\tconds, ok := cond.Value.([]*universalFilterCondition)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"invalid logical condition value type\")\n\t}\n\n\tvar condResult *convertResult\n\tfor _, childCond := range conds {\n\t\tchildRes, err := c.convertCondition(childCond, counter)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tif childRes == nil || childRes.exprStr == \"\" {\n\t\t\tcontinue\n\t\t}\n\t\tif condResult == nil {\n\t\t\tcondResult = childRes\n\t\t\tcontinue\n\t\t}\n\n\t\tcondResult.exprStr = fmt.Sprintf(\n\t\t\t\"(%s) %s (%s)\",","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/application/repository/retriever/milvus/filter.go#L87-L123","documentation":"convertLogicalCondition type-asserts cond.Value to []*universalFilterCondition to obtain the child conditions of a logical node. If Value is non-nil but holds any other type, it returns 'invalid logical condition value type'. This protects the converter from malformed filter trees where a logical node's payload was built with the wrong element type.","triggerScenarios":"Building a logical condition whose Value is []universalFilterCondition (no pointer), []*someOtherCondType, a single *universalFilterCondition, or a raw map/slice from JSON decoding — any non-[]*universalFilterCondition payload.","commonSituations":"JSON/YAML filter decoding producing map[string]any instead of typed conditions; refactors changing the condition struct without updating group builders; mixing condition types from two different filter packages.","solutions":["Ensure logical conditions are constructed only via the helper that stores []*universalFilterCondition in Value.","Fix the caller constructing the tree so children are appended as *universalFilterCondition pointers.","If input comes from JSON, decode into the typed condition structs first, then build the tree; never pass raw decoded values.","Add a constructor (e.g. newLogicalCond(op string, children []*universalFilterCondition)) and forbid direct Value assignment."],"exampleFix":"// before\nnode := &universalFilterCondition{Operator: \"AND\", Value: children} // children is []universalFilterCondition\n// after\nptrs := make([]*universalFilterCondition, len(children))\nfor i := range children {\n\tptrs[i] = &children[i]\n}\nnode := &universalFilterCondition{Operator: \"AND\", Value: ptrs}","handlingStrategy":"type-guard","validationCode":"if kids, ok := cond.Value.([]*universalFilterCondition); !ok || len(kids) == 0 {\n\treturn errors.New(\"logical condition must carry []*universalFilterCondition children\")\n}","typeGuard":"func asChildConditions(v any) ([]*universalFilterCondition, bool) {\n\tkids, ok := v.([]*universalFilterCondition)\n\treturn kids, ok && len(kids) > 0\n}","tryCatchPattern":null,"preventionTips":["Store logical children exclusively as []*universalFilterCondition via a dedicated constructor.","Decode JSON filters into typed structs before assembling the tree.","Never assign raw decoded values (map[string]any, []any) to Value.","Add a unit test asserting the converter round-trips every logical node type."],"tags":["milvus","go","filter","type-assertion"],"backgroundTag":"invalid-filter-value-type","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}