{"record":{"id":"a21ef691da42bd12","repo":"dgraph-io/dgraph","slug":"expected-a-float-but-got-v","errorCode":null,"errorMessage":"Expected a float but got %v","messagePattern":"Expected a float but got (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"dql/parser.go","lineNumber":330,"sourceCode":"\t\treturn types.Val{}, errors.Errorf(\"No value found\")\n\t}\n\n\tswitch typ {\n\tcase \"int\":\n\t\t{\n\t\t\tif i, err := strconv.ParseInt(v.Value, 0, 64); err != nil {\n\t\t\t\treturn types.Val{}, errors.Wrapf(err, \"Expected an int but got %v\", v.Value)\n\t\t\t} else {\n\t\t\t\treturn types.Val{\n\t\t\t\t\tTid:   types.IntID,\n\t\t\t\t\tValue: i,\n\t\t\t\t}, nil\n\t\t\t}\n\t\t}\n\tcase \"float\":\n\t\t{\n\t\t\tif i, err := strconv.ParseFloat(v.Value, 64); err != nil {\n\t\t\t\treturn types.Val{}, errors.Wrapf(err, \"Expected a float but got %v\", v.Value)\n\t\t\t} else {\n\t\t\t\treturn types.Val{\n\t\t\t\t\tTid:   types.FloatID,\n\t\t\t\t\tValue: i,\n\t\t\t\t}, nil\n\t\t\t}\n\t\t}\n\tcase \"bool\":\n\t\t{\n\t\t\tif i, err := strconv.ParseBool(v.Value); err != nil {\n\t\t\t\treturn types.Val{}, errors.Wrapf(err, \"Expected a bool but got %v\", v.Value)\n\t\t\t} else {\n\t\t\t\treturn types.Val{\n\t\t\t\t\tTid:   types.BoolID,\n\t\t\t\t\tValue: i,\n\t\t\t\t}, nil\n\t\t\t}\n\t\t}","sourceCodeStart":312,"sourceCodeEnd":348,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/dql/parser.go#L312-L348","documentation":"parseValue parses variables of type \"float\" with strconv.ParseFloat(v.Value, 64). A non-numeric string fails the parse and is wrapped with 'Expected a float but got %v', including the raw value for debugging.","triggerScenarios":"Supplying a variable with Type \"float\" whose Value cannot be parsed as a float64 — e.g. \"$score\": \"high\", \"3,14\" (comma decimal), or an empty-ish non-numeric string.","commonSituations":"Locale-formatted numbers with comma decimal separators coming from clients; passing integer-typed units or booleans into float variables; JSON unmarshalling into string variables that lose numeric formatting.","solutions":["Ensure the value is a valid float literal (digits, optional sign, optional exponent, '.' decimal point)","Replace locale decimal commas with dots before submitting the variables map","Verify the variable's declared type matches the data; change to \"int\" if values are whole numbers","Pre-validate with strconv.ParseFloat on the caller side to fail before the query is parsed"],"exampleFix":"// before\nvars := map[string]string{\"$price\": \"19,99\"}\n// after\nvars := map[string]string{\"$price\": \"19.99\"}","handlingStrategy":"validation","validationCode":"if _, err := strconv.ParseFloat(vars[\"$price\"], 64); err != nil {\n  return fmt.Errorf(\"$price must be a float: %w\", err)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Normalize decimal commas to dots before submission","Keep numbers as numbers end-to-end; stringify only at the last step","Pre-validate every float-typed variable with strconv.ParseFloat"],"tags":["dgraph","dql","variables","type-parsing","float"],"backgroundTag":"query-variable-type-mismatch","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}