{"record":{"id":"1b8bf3fbbd4cf432","repo":"theonedev/onedev","slug":"cannot-order-by-field-fieldname-1b8bf3","errorCode":null,"errorMessage":"Cannot order by field: ${fieldName}","messagePattern":"Cannot order by field: (.+?)","errorType":"exception","errorClass":"ExplicitException","httpStatus":null,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/search/entity/project/ProjectQuery.java","lineNumber":241,"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<Project> visitNotCriteria(NotCriteriaContext ctx) {\n\t\t\t\t\t\treturn new NotCriteria<>(visit(ctx.criteria()));\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t}.visit(criteriaContext);\n\t\t\t} else {\n\t\t\t\tprojectCriteria = null;\n\t\t\t}\n\n\t\t\tList<EntitySort> projectSorts = 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 projectSort = new EntitySort();\n\t\t\t\tprojectSort.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\tprojectSort.setDirection(DESCENDING);\n\t\t\t\t\telse\n\t\t\t\t\t\tprojectSort.setDirection(ASCENDING);\n\t\t\t\t} else {\n\t\t\t\t\tprojectSort.setDirection(sortField.getDefaultDirection());\n\t\t\t\t}\n\t\t\t\tprojectSorts.add(projectSort);\n\t\t\t}\n\t\t\t\n\t\t\treturn new ProjectQuery(projectCriteria, projectSorts);\n\t\t} else {\n\t\t\treturn new ProjectQuery();\n\t\t}","sourceCodeStart":223,"sourceCodeEnd":259,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/search/entity/project/ProjectQuery.java#L223-L259","documentation":"ProjectQuery.parse resolves each 'order by' field name against the static SORT_FIELDS map; unknown names throw ExplicitException('Cannot order by field: X'). Only whitelisted sortable fields (e.g. name, last activity) may be used in 'order by'.","triggerScenarios":"A query ending in 'order by \"someField\"' where someField is queryable but not in ProjectQuery.SORT_FIELDS.","commonSituations":"Sorting by fields that are filterable but not sortable (e.g. description); typos in field names; queries ported from other entity types with different sort fields.","solutions":["Order only by fields listed in ProjectQuery.SORT_FIELDS (e.g. \"name\", \"last activity\").","Drop the order-by clause and sort results client-side if the field is unsupported.","Catch ExplicitException and present allowed sort fields to the user.","Correct the field-name spelling/casing to match the whitelist exactly."],"exampleFix":"// before\n\"... order by \\\"description\\\"\"  // not sortable\n// after\n\"... order by \\\"name\\\" desc\"","handlingStrategy":"validation","validationCode":"// pre-check sort field\nif (!Set.of(\"name\", \"last activity\").contains(sortField)) throw new IllegalArgumentException(\"Not sortable: \" + sortField);","typeGuard":"null","tryCatchPattern":"try { q = ProjectQuery.parse(text); } catch (ExplicitException e) { showAllowedSortFields(e); }","preventionTips":["Order only by fields present in ProjectQuery.SORT_FIELDS","Do not assume filterable fields are sortable","Sort client-side when the field is unsupported","Validate order-by clauses in saved query editors"],"tags":["query","sorting","validation"],"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-14T05:17:10.506Z"}