theonedev/onedev · error · ExplicitException

Cannot order by field:

Error message

Cannot order by field: 

What it means

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.

Solutions

  1. Correct the field name in the 'order by' clause to a valid sortable issue field.
  2. Check the project's issue setting to confirm the custom field exists and is of an orderable type (choice, date, date-time, integer, iteration).
  3. Remove the 'order by' clause if sorting is not needed.
  4. Parse with validation disabled if the field validity is checked elsewhere.

Example fix

// before
"order by Priority"
// after (case/type-correct field, or a built-in sortable field)
"order by priority" // or: "order by Number"
Defensive patterns

Strategy: validation

Validate before calling

// Validate order-by field before parsing
var sortable = Set.of("number", "priority", "submitDate", "status", "title", "updateDate");
String field = extractOrderByField(query);
if (field != null && !sortable.contains(field.toLowerCase())) {
    throw new IllegalArgumentException("Cannot order by field: " + field);
}

Try / catch

// catch ExplicitException from query parse
try {
    IssueQuery query = IssueQuery.parse(project, sortField, option);
} catch (ExplicitException e) {
    showQueryError(e.getMessage());
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of theonedev/onedev@d44925c47c (2026-09-06). Data as JSON: /api/errors/d628212c79981212. Report an issue: GitHub.

Appendix: source

Thrown at server-core/src/main/java/io/onedev/server/search/entity/issue/IssueQuery.java:533

					public Criteria<Issue> visitNotCriteria(NotCriteriaContext ctx) {
						return new NotCriteria<>(visit(ctx.criteria()));
					}

				}.visit(criteriaContext);
			} else {
				issueCriteria = null;
			}

			List<EntitySort> issueSorts = new ArrayList<>();
			for (OrderContext order : queryContext.order()) {
				var fieldName = getValue(order.Quoted().getText());
				var sortField = SORT_FIELDS.get(fieldName);
				if (validate && sortField == null) {
					FieldSpec fieldSpec = getGlobalIssueSetting().getFieldSpec(fieldName);
					if (validate && !(fieldSpec instanceof ChoiceField) && !(fieldSpec instanceof DateField)
							&& !(fieldSpec instanceof DateTimeField) && !(fieldSpec instanceof IntegerField)
							&& !(fieldSpec instanceof IterationChoiceField)) {
						throw new ExplicitException("Cannot order by field: " + fieldName);
					}
				}

				EntitySort issueSort = new EntitySort();
				issueSort.setField(fieldName);
				if (order.direction != null) {
					if (order.direction.getText().equals("desc"))
						issueSort.setDirection(DESCENDING);
					else
						issueSort.setDirection(ASCENDING);
				} else if (sortField != null) {
					issueSort.setDirection(sortField.getDefaultDirection());
				} else {
					issueSort.setDirection(ASCENDING);
				}
				issueSorts.add(issueSort);
			}

View on GitHub (pinned to d44925c47c)