{"record":{"id":"d13033eaa7b0db88","repo":"vxcontrol/pentagi","slug":"errtasksinvalidrequest","errorCode":"ErrTasksInvalidRequest","errorMessage":"group field not found","messagePattern":"group field not found","errorType":"http","errorClass":null,"httpStatus":400,"severity":"warning","filePath":"backend/pkg/server/services/tasks.go","lineNumber":108,"sourceCode":"\t\t}\n\t} else if slices.Contains(privs, \"tasks.view\") {\n\t\tscope = func(db *gorm.DB) *gorm.DB {\n\t\t\treturn db.\n\t\t\t\tJoins(\"INNER JOIN flows f ON f.id = tasks.flow_id\").\n\t\t\t\tWhere(\"f.id = ? AND f.user_id = ?\", flowID, uid)\n\t\t}\n\t} else {\n\t\tlogger.FromContext(c).Errorf(\"error filtering user role permissions: permission not found\")\n\t\tresponse.Error(c, response.ErrNotPermitted, nil)\n\t\treturn\n\t}\n\n\tquery.Init(\"tasks\", tasksSQLMappers)\n\n\tif query.Group != \"\" {\n\t\tif _, ok := tasksSQLMappers[query.Group]; !ok {\n\t\t\tlogger.FromContext(c).Errorf(\"error finding tasks grouped: group field not found\")\n\t\t\tresponse.Error(c, response.ErrTasksInvalidRequest, errors.New(\"group field not found\"))\n\t\t\treturn\n\t\t}\n\n\t\tvar respGrouped tasksGrouped\n\t\tif respGrouped.Total, err = query.QueryGrouped(s.db, &respGrouped.Grouped, scope); err != nil {\n\t\t\tlogger.FromContext(c).WithError(err).Errorf(\"error finding tasks grouped\")\n\t\t\tresponse.Error(c, response.ErrInternal, err)\n\t\t\treturn\n\t\t}\n\n\t\tresponse.Success(c, http.StatusOK, respGrouped)\n\t\treturn\n\t}\n\n\tif resp.Total, err = query.Query(s.db, &resp.Tasks, scope); err != nil {\n\t\tlogger.FromContext(c).WithError(err).Errorf(\"error finding tasks\")\n\t\tresponse.Error(c, response.ErrInternal, err)\n\t\treturn","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/vxcontrol/pentagi/blob/ea665308baaff015b226f308438a68d929d0f29b/backend/pkg/server/services/tasks.go#L90-L126","documentation":"GetFlowTasks supports grouped task listings. The `group` query parameter is checked against tasksSQLMappers; if it is set but not found in that map, the handler returns ErrTasksInvalidRequest before running the grouped query.","triggerScenarios":"GET /flows/{flow_id}/tasks?group=<field> where <field> is not a key of tasksSQLMappers (unknown/renamed/unmapped column).","commonSituations":"Flow overview dashboards grouping tasks by fields like priority or result that are not mapped; clients reusing group values from subtasks/termlogs endpoints whose mappers differ; frontend/backend drift after a mapper cleanup.","solutions":["Use a group field present in tasksSQLMappers in backend/pkg/server/services/tasks.go.","Drop the group parameter for the default listing.","Update clients to the current groupable fields after schema/mapper changes.","Add the field to tasksSQLMappers if server-side grouping by it is required."],"exampleFix":"// before\nGET /api/v1/flows/5/tasks?group=priority\n// after\nGET /api/v1/flows/5/tasks?group=status","handlingStrategy":"validation","validationCode":"const TASKS_GROUP_FIELDS = ['status', 'created_at']; // keys of tasksSQLMappers\nif (group && !TASKS_GROUP_FIELDS.includes(group)) {\n  throw new Error(`invalid group field for tasks: ${group}`);\n}","typeGuard":"function isValidTaskGroup(g) {\n  return typeof g === 'string' && TASKS_GROUP_FIELDS.includes(g);\n}","tryCatchPattern":"try {\n  return await api.getFlowTasks(flowId, { group });\n} catch (e) {\n  if (e.code === 'ErrTasksInvalidRequest' && e.message === 'group field not found') {\n    return await api.getFlowTasks(flowId, {});\n  }\n  throw e;\n}","preventionTips":["Use only fields defined in tasksSQLMappers as group values.","Validate the group query parameter client-side before sending.","Update clients after any backend mapper rename; never hardcode group names in URLs.","Handle this 400 by dropping the group parameter and retrying once."],"tags":["rest-api","validation","query-params","http-400"],"backgroundTag":"invalid-group-field","analyzedSha":"ea665308baaff015b226f308438a68d929d0f29b","analyzedAt":"2026-09-01T14:16:31.421Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}