{"record":{"id":"d628212c79981212","repo":"theonedev/onedev","slug":"cannot-order-by-field-d62821","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/issue/IssueQuery.java","lineNumber":533,"sourceCode":"\t\t\t\t\tpublic Criteria<Issue> 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\tissueCriteria = null;\n\t\t\t}\n\n\t\t\tList<EntitySort> issueSorts = 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 (validate && sortField == null) {\n\t\t\t\t\tFieldSpec fieldSpec = getGlobalIssueSetting().getFieldSpec(fieldName);\n\t\t\t\t\tif (validate && !(fieldSpec instanceof ChoiceField) && !(fieldSpec instanceof DateField)\n\t\t\t\t\t\t\t&& !(fieldSpec instanceof DateTimeField) && !(fieldSpec instanceof IntegerField)\n\t\t\t\t\t\t\t&& !(fieldSpec instanceof IterationChoiceField)) {\n\t\t\t\t\t\tthrow new ExplicitException(\"Cannot order by field: \" + fieldName);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tEntitySort issueSort = new EntitySort();\n\t\t\t\tissueSort.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\tissueSort.setDirection(DESCENDING);\n\t\t\t\t\telse\n\t\t\t\t\t\tissueSort.setDirection(ASCENDING);\n\t\t\t\t} else if (sortField != null) {\n\t\t\t\t\tissueSort.setDirection(sortField.getDefaultDirection());\n\t\t\t\t} else {\n\t\t\t\t\tissueSort.setDirection(ASCENDING);\n\t\t\t\t}\n\t\t\t\tissueSorts.add(issueSort);\n\t\t\t}\n","sourceCodeStart":515,"sourceCodeEnd":551,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/search/entity/issue/IssueQuery.java#L515-L551","documentation":"IssueQuery.parse validates the 'order by' field name against the set of sortable SORT_FIELDS. If the field is not a known sort field and (in validate mode) is not a custom field spec of type ChoiceField, DateField, DateTimeField, IntegerField, or IterationChoiceField, an ExplicitException is thrown naming the offending field.","triggerScenarios":"Parsing an issue query with an 'order by <fieldName>' clause where fieldName is not a built-in sortable field and not an orderable custom field (choice/date/integer/iteration), with validation enabled.","commonSituations":"Typo in the sort field name; using a text or user custom field in order by; copying a query that sorts by a field type that is not orderable in this project's issue setting.","solutions":["Correct the field name in the 'order by' clause to a valid sortable issue field.","Check the project's issue setting to confirm the custom field exists and is of an orderable type (choice, date, date-time, integer, iteration).","Remove the 'order by' clause if sorting is not needed.","Parse with validation disabled if the field validity is checked elsewhere."],"exampleFix":"// before\n\"order by Priority\"\n// after (case/type-correct field, or a built-in sortable field)\n\"order by priority\" // or: \"order by Number\"","handlingStrategy":"validation","validationCode":"// Validate order-by field before parsing\nvar sortable = Set.of(\"number\", \"priority\", \"submitDate\", \"status\", \"title\", \"updateDate\");\nString field = extractOrderByField(query);\nif (field != null && !sortable.contains(field.toLowerCase())) {\n    throw new IllegalArgumentException(\"Cannot order by field: \" + field);\n}","typeGuard":null,"tryCatchPattern":"// catch ExplicitException from query parse\ntry {\n    IssueQuery query = IssueQuery.parse(project, sortField, option);\n} catch (ExplicitException e) {\n    showQueryError(e.getMessage());\n}","preventionTips":["Keep an allowlist of sortable fields in query-builder UIs.","Verify custom field types support ordering before offering them in sort pickers.","Test saved queries after issue-setting changes."],"tags":["query-parsing","validation","issue-search"],"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-14T00:17:10.932Z"}