{"record":{"id":"c958c6c3e3b96e92","repo":"theonedev/onedev","slug":"cannot-order-by-field","errorCode":null,"errorMessage":"Cannot order by field: ","messagePattern":"Cannot order by field: ","errorType":"exception","errorClass":"ExplicitException","httpStatus":null,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/search/entity/agent/AgentQuery.java","lineNumber":214,"sourceCode":"\t\t\t\t\t\treturn new AndCriteria<>(childCriterias);\n\t\t\t\t\t}\n\n\t\t\t\t\t@Override\n\t\t\t\t\tpublic Criteria<Agent> visitNotCriteria(NotCriteriaContext ctx) {\n\t\t\t\t\t\treturn new NotCriteria<>(visit(ctx.criteria()));\n\t\t\t\t\t}\n\n\t\t\t\t}.visit(criteriaContext);\n\t\t\t} else {\n\t\t\t\tagentCriteria = null;\n\t\t\t}\n\n\t\t\tList<EntitySort> agentSorts = new ArrayList<>();\n\t\t\tfor (OrderContext order: queryContext.order()) {\n\t\t\t\tvar fieldName = getValue(order.Quoted().getText());\n\t\t\t\tvar sortField = SORT_FIELDS.get(fieldName);\n\t\t\t\tif (sortField == null)\n\t\t\t\t\tthrow new ExplicitException(\"Cannot order by field: \" + fieldName);\n\t\t\t\t\n\t\t\t\tEntitySort agentSort = new EntitySort();\n\t\t\t\tagentSort.setField(fieldName);\n\t\t\t\tif (order.direction != null) {\n\t\t\t\t\tif (order.direction.getText().equals(\"desc\"))\n\t\t\t\t\t\tagentSort.setDirection(DESCENDING);\n\t\t\t\t\telse\n\t\t\t\t\t\tagentSort.setDirection(ASCENDING);\n\t\t\t\t} else {\n\t\t\t\t\tagentSort.setDirection(sortField.getDefaultDirection());\n\t\t\t\t}\n\t\t\t\tagentSorts.add(agentSort);\n\t\t\t}\n\t\t\t\n\t\t\treturn new AgentQuery(agentCriteria, agentSorts);\n\t\t} else {\n\t\t\treturn new AgentQuery();\n\t\t}","sourceCodeStart":196,"sourceCodeEnd":232,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/search/entity/agent/AgentQuery.java#L196-L232","documentation":"AgentQuery.parse validates each order-by field name against the query's fixed SORT_FIELDS set; an unknown field cannot be mapped to a sort property and parsing aborts. The message carries the offending field name.","triggerScenarios":"Supplying an 'order by' field in an agent query that is not among the allowed sort fields, e.g. order(\"description\") when only id/name fields are sortable.","commonSituations":"Ordering by an agent attribute or custom field; typo in the field name; assuming all query fields are also sortable.","solutions":["Use only fields listed in AgentQuery.SORT_FIELDS (e.g. \"name\")","Fix the field-name spelling","Sort client-side if the field isn't server-sortable"],"exampleFix":"// before\nq = \"order by description\"\n// after\nq = \"order by \\\"name\\\"\"","handlingStrategy":"validation","validationCode":"if (!AgentQuery.SORT_FIELDS.containsKey(sortField)) throw new IllegalArgumentException(\"not sortable: \" + sortField);","typeGuard":null,"tryCatchPattern":"try { new AgentQuery(q); } catch (ExplicitException e) { /* drop or replace the order clause */ }","preventionTips":["Order only by fields exposed in SORT_FIELDS","Strip order clauses when reusing queries across entity types","Keep a whitelist of sortable fields in UI dropdowns"],"tags":["query-syntax","sorting","onedev"],"backgroundTag":"invalid-query-parameter","analyzedSha":"d44925c47c37992c828ea673a5f9620539bc3ff2","analyzedAt":"2026-09-06T07:18:27.995Z","contentChangedAt":"2026-09-06T07:18:27.995Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}