{"record":{"id":"8c0e00277f7bf4ab","repo":"SigNoz/signoz","slug":"unknown-variable-s","errorCode":null,"errorMessage":"unknown variable %s","messagePattern":"unknown variable (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/query-service/app/parser.go","lineNumber":725,"sourceCode":"// allowed functions.\nfunc validateExpressions(expressions []string, funcs map[string]govaluate.ExpressionFunction, cq *v3.CompositeQuery) []error {\n\tvar errs []error\n\tfor _, exp := range expressions {\n\t\tevalExp, err := govaluate.NewEvaluableExpressionWithFunctions(exp, funcs)\n\t\tif err != nil {\n\t\t\terrs = append(errs, fmt.Errorf(\"invalid expression %s: %v\", exp, err))\n\t\t\tcontinue\n\t\t}\n\t\tfor _, v := range evalExp.Vars() {\n\t\t\tvar hasVariable bool\n\t\t\tfor _, q := range cq.BuilderQueries {\n\t\t\t\tif q.Expression == v {\n\t\t\t\t\thasVariable = true\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\t\t\tif !hasVariable {\n\t\t\t\terrs = append(errs, fmt.Errorf(\"unknown variable %s\", v))\n\t\t\t}\n\t\t}\n\t}\n\treturn errs\n}\n\n// chTransformQuery transforms the clickhouse query with the given variables\n// it is used to check what would be the query if variables are selected as __all__.\n// for now, this is just a pass through, but in the future, we will use it to\n// dashboard variables\n// TODO(srikanthccv): version based query replacement\nfunc chTransformQuery(query string, variables map[string]interface{}) {\n\tvarsForTransform := make([]chVariables.VariableValue, 0, len(variables))\n\tfor name := range variables {\n\t\tvarsForTransform = append(varsForTransform, chVariables.VariableValue{\n\t\t\tName:        name,\n\t\t\tValues:      []string{\"__all__\"},\n\t\t\tIsSelectAll: true,","sourceCodeStart":707,"sourceCodeEnd":743,"githubUrl":"https://github.com/SigNoz/signoz/blob/5069bf80b08f1f00d7e014eccc09902f9871004f/pkg/query-service/app/parser.go#L707-L743","documentation":"Every variable referenced in a builder expression must correspond to another builder query's Expression (its name). If a variable like C is used but no builder query defines it, this error is returned from validateExpressions during query-range validation.","triggerScenarios":"Expression 'A + C' where only queries A and B exist; renaming/deleting a query that is still referenced by a formula.","commonSituations":"Editing a dashboard panel and removing a query without updating dependent formulas; typos in variable names; API-built composite queries missing a referenced query block.","solutions":["Add a builder query whose name matches the variable, or fix the variable name in the expression","Ensure referenced queries are included in the same composite query payload","When deleting a query, first remove expressions that reference it"],"exampleFix":"// before\n{\"expression\": \"A + C\", \"queries\": [A, B]}\n// after\n{\"expression\": \"A + B\", \"queries\": [A, B]}","handlingStrategy":"validation","validationCode":"defined := map[string]bool{}\nfor name, q := range cq.BuilderQueries { defined[q.Expression] = true; defined[name] = true }\nfor _, v := range evalExp.Vars() { if !defined[v] { return fmt.Errorf(\"unknown variable %s\", v) } }","typeGuard":"func allVarsDefined(expr string, cq *v3.CompositeQuery) bool { /* compile with govaluate, check Vars() ⊆ builderQueries keys */ return true }","tryCatchPattern":null,"preventionTips":["When renaming/deleting queries, scan all expressions for stale references","Build composite queries via a helper that checks variable closure"],"tags":["signoz","query-builder","expression","unknown-variable"],"backgroundTag":"unresolved-reference","analyzedSha":"5069bf80b08f1f00d7e014eccc09902f9871004f","analyzedAt":"2026-08-28T06:22:12.824Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}