{"record":{"id":"bb99b05aad001c64","repo":"gohugoio/hugo","slug":"invalid-intersect-values","errorCode":null,"errorMessage":"invalid intersect values","messagePattern":"invalid intersect values","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/collections/where.go","lineNumber":294,"sourceCode":"\t\tif op == \"not in\" {\n\t\t\treturn !r, nil\n\t\t}\n\t\treturn r, nil\n\tcase \"intersect\":\n\t\tr, err := ns.Intersect(slv, slmv)\n\t\tif err != nil {\n\t\t\treturn false, err\n\t\t}\n\n\t\tif reflect.TypeOf(r).Kind() == reflect.Slice {\n\t\t\ts := reflect.ValueOf(r)\n\n\t\t\tif s.Len() > 0 {\n\t\t\t\treturn true, nil\n\t\t\t}\n\t\t\treturn false, nil\n\t\t}\n\t\treturn false, errors.New(\"invalid intersect values\")\n\tcase \"like\":\n\t\tif svp != nil && smvp != nil {\n\t\t\tre, err := hstrings.GetOrCompileRegexp(*smvp)\n\t\t\tif err != nil {\n\t\t\t\treturn false, err\n\t\t\t}\n\t\t\tif re.MatchString(*svp) {\n\t\t\t\treturn true, nil\n\t\t\t}\n\t\t\treturn false, nil\n\t\t}\n\tdefault:\n\t\treturn false, errors.New(\"no such operator\")\n\t}\n\treturn false, nil\n}\n\nfunc evaluateSubElem(ctx, obj reflect.Value, elemName string) (reflect.Value, error) {","sourceCodeStart":276,"sourceCodeEnd":312,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/tpl/collections/where.go#L276-L312","documentation":"When using the `intersect` operator inside `where`, Hugo calls `ns.Intersect(slv, slmv)` and expects the result to be a slice. If `reflect.TypeOf(r).Kind()` is not `reflect.Slice`, this error is returned. This is a defensive guard against an unexpected return type from Intersect — typically a sign that the operands were not valid comparable slices of the same element kind.","triggerScenarios":"Using the intersect operator in `where`, e.g. `{{ where .Pages \"Tags\" \"intersect\" $tagSlice }}`, where the key field does not resolve to a slice or the operands' element types are incompatible so Intersect cannot produce a slice result.","commonSituations":"A developer applies the `intersect` operator against a field that is sometimes a scalar (string) rather than a slice, or against a nil-valued field that yields a non-slice reflect.Value from Intersect.","solutions":["Ensure the key field on every element is a slice of a comparable type (e.g. `[]string`).","Verify both operands are slices before using the intersect operator.","If the field may be a single value, wrap it: `{{ where .Pages \"Tags\" \"intersect\" (slice $tag) }}` and ensure Tags is always a slice."],"exampleFix":"// before\n{{ where .Pages \"Tags\" \"intersect\" $singleTagString }}\n// after\n{{ where .Pages \"Tags\" \"intersect\" (slice $singleTagString) }}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"func isSliceOfSlices(v any) bool {\n    rv := reflect.ValueOf(v)\n    if rv.Kind() != reflect.Slice { return false }\n    return rv.Type().Elem().Kind() == reflect.Slice\n}","tryCatchPattern":null,"preventionTips":["Ensure the key field is a slice on all elements when using the intersect operator.","Verify both operands are slices of comparable elements.","Test with homogeneous collections before deploying."],"tags":["hugo","template","collections","where","intersect"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}