{"record":{"id":"8a3999e7e042a53d","repo":"dgraph-io/dgraph","slug":"one-argument-expected-in-s-but-got-d","errorCode":null,"errorMessage":"One argument expected in %s, but got %d.","messagePattern":"One argument expected in (.+?), but got (.+?)\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"worker/task.go","lineNumber":2437,"sourceCode":"// commonTypeIDs is list of type ids which are more common. In preprocessFilter() we keep converted\n// values for these typeIDs at every function node.\nvar commonTypeIDs = [...]types.TypeID{types.StringID, types.IntID, types.FloatID,\n\ttypes.DateTimeID, types.BoolID, types.DefaultID}\n\nfunc preprocessFilter(tree *pb.FilterTree) (*facetsTree, error) {\n\tif tree == nil {\n\t\treturn nil, nil\n\t}\n\tftree := &facetsTree{}\n\tftree.op = strings.ToLower(tree.Op)\n\tif tree.Func != nil {\n\t\tftree.function = &facetsFunc{}\n\t\tftree.function.key = tree.Func.Key\n\t\tftree.function.args = tree.Func.Args\n\n\t\tfnType, fname := parseFuncTypeHelper(tree.Func.Name)\n\t\tif len(tree.Func.Args) != 1 {\n\t\t\treturn nil, errors.Errorf(\"One argument expected in %s, but got %d.\",\n\t\t\t\tfname, len(tree.Func.Args))\n\t\t}\n\n\t\tftree.function.name = fname\n\t\tftree.function.fnType = fnType\n\n\t\tswitch fnType {\n\t\tcase compareAttrFn:\n\t\t\tftree.function.val = types.Val{Tid: types.StringID, Value: []byte(tree.Func.Args[0])}\n\t\t\tftree.function.typesToVal = make(map[types.TypeID]types.Val, len(commonTypeIDs))\n\t\t\tfor _, typeID := range commonTypeIDs {\n\t\t\t\t// TODO: if conversion is not possible we are not putting anything to map. In\n\t\t\t\t// applyFacetsTree we check if entry for a type is not present, we try to convert\n\t\t\t\t// it. This double conversion can be avoided.\n\t\t\t\tcv, err := types.Convert(ftree.function.val, typeID)\n\t\t\t\tif err != nil {\n\t\t\t\t\tcontinue\n\t\t\t\t}","sourceCodeStart":2419,"sourceCodeEnd":2455,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/worker/task.go#L2419-L2455","documentation":"Facet functions in Dgraph take exactly one argument (the facet value to compare). During parsing/preprocessing of a facet filter tree, the number of function arguments is validated; anything other than 1 triggers this error naming the function type and the actual count.","triggerScenarios":"Writing @facets(eq(score, 1, 2)) or @facets(gt(weight)) — any facet function call with zero or two-plus arguments inside a facet filter.","commonSituations":"Misreading between(a,b) as usable in facets (between is not a one-arg facet fn); adding a comparison constant plus default value; copy-paste from regular filter syntax.","solutions":["Pass exactly one argument to the facet function, e.g. @facets(eq(name, \"alice\")).","If a range is needed, compose two facet filters (ge and le) instead of passing two args to one fn.","Note: `between` is not a valid facet-filter function; use ge/lt combinations."],"exampleFix":"// before\nfriend @facets(between(score, 1, 10))\n// after\nfriend @facets(ge(score, 1)) @facets(le(score, 10))","handlingStrategy":"validation","validationCode":"function validateFacetFnArgs(query) {\n  for (const m of query.matchAll(/@facets\\(\\w+\\(([^)]*)\\)/g)) {\n    const argc = m[1].split(\",\").filter(s => s.trim() !== \"\").length;\n    if (argc !== 1) throw new Error(`Facet fn needs exactly 1 arg, got ${argc}: @facets(${m[0]})`);\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  return await txn.query(query);\n} catch (e) {\n  if (/One argument expected/.test(String(e))) {\n    // surface the malformed facet expression to the caller\n  }\n  throw e;\n}","preventionTips":["Facet functions take exactly one argument.","For ranges, compose ge + le instead of multi-arg calls.","Add query-lint tests that parse every @facets expression."],"tags":["dgraph","query","facets","arguments"],"backgroundTag":"wrong-argument-count","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}