{"record":{"id":"0197548c30c1a294","repo":"theonedev/onedev","slug":"cannot-order-by-field-fieldname-019754","errorCode":null,"errorMessage":"\"Cannot order by field: \" + fieldName","messagePattern":"\"Cannot order by field: \" \\+ fieldName","errorType":"exception","errorClass":"ExplicitException","httpStatus":null,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/search/entity/workspace/WorkspaceQuery.java","lineNumber":260,"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<Workspace> 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\tworkspaceCriteria = null;\n\t\t\t}\n\n\t\t\tList<EntitySort> workspaceSorts = 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\n\t\t\t\tEntitySort workspaceSort = new EntitySort();\n\t\t\t\tworkspaceSort.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\tworkspaceSort.setDirection(DESCENDING);\n\t\t\t\t\telse\n\t\t\t\t\t\tworkspaceSort.setDirection(ASCENDING);\n\t\t\t\t} else {\n\t\t\t\t\tworkspaceSort.setDirection(sortField.getDefaultDirection());\n\t\t\t\t}\n\t\t\t\tworkspaceSorts.add(workspaceSort);\n\t\t\t}\n\n\t\t\treturn new WorkspaceQuery(workspaceCriteria, workspaceSorts);\n\t\t} else {\n\t\t\treturn new WorkspaceQuery();\n\t\t}","sourceCodeStart":242,"sourceCodeEnd":278,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/search/entity/workspace/WorkspaceQuery.java#L242-L278","documentation":"Query-parser guard in WorkspaceQuery.parse: the query's order-by clause names a field not present in SORT_FIELDS, so the sort cannot be translated to an index field; ExplicitException reports the offending fieldName. Fix: order by one of the supported workspace query fields.","triggerScenarios":"A query with an `order by` clause naming a field not in SORT_FIELDS, e.g. `order by (\"commit\")`.","commonSituations":"Sorting by fields that exist as query criteria but not as sortable fields; typos in sort field names; reusing sort fields from other entity queries.","solutions":["Order only by sortable fields listed in WorkspaceQuery.SORT_FIELDS (e.g. \"number\", \"name\", \"submit date\").","Remove the order by clause to use default ordering.","Fix the field name spelling."],"exampleFix":"// before\norder by (\"commit\")\n// after\norder by (\"submit date\") desc","handlingStrategy":"validation","validationCode":"Set<String> sortableFields = Set.of(\"number\", \"name\", \"submit date\", \"create date\", \"active date\");\nif (!sortableFields.contains(orderField)) throw new IllegalArgumentException(\"Cannot order by \" + orderField);","typeGuard":null,"tryCatchPattern":"try {\n    var query = WorkspaceQuery.parse(queryText);\n} catch (ExplicitException e) {\n    // drop or fix the order by clause\n}","preventionTips":["Order only by fields in WorkspaceQuery.SORT_FIELDS","Use default ordering when unsure"],"tags":["search","query","ordering"],"backgroundTag":"invalid-argument-value","analyzedSha":"d44925c47c37992c828ea673a5f9620539bc3ff2","analyzedAt":"2026-09-06T07:18:27.995Z","contentChangedAt":"2026-09-06T07:18:27.995Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}