Bug
JobListParams.toDBParams() in job_list_params.go has an inverted guard when validating state filters for JobListOrderByFinalizedAt.
Affected code (line ~244)
if p.sortField == JobListOrderByFinalizedAt {
currentNonFinalizedStates := make([]rivertype.JobState, 0, len(p.states))
for _, state := range p.states {
switch state {
case rivertype.JobStateAvailable, rivertype.JobStatePending, ...:
currentNonFinalizedStates = append(currentNonFinalizedStates, state)
case rivertype.JobStateCancelled, rivertype.JobStateCompleted, rivertype.JobStateDiscarded:
}
}
// Comment says: "user overrode the States list with only non-finalized states"
if len(currentNonFinalizedStates) == 0 { // ← INVERTED
return nil, fmt.Errorf("cannot order by finalized_at with non-finalized state filters %+v",
currentNonFinalizedStates)
}
}
What's wrong
The comment says the guard is checking for "only non-finalized states" — but the condition len(currentNonFinalizedStates) == 0 is true when there are zero non-finalized states, meaning all states are finalized. That's actually the correct usage for JobListOrderByFinalizedAt.
The inverted conditions:
| States passed |
currentNonFinalizedStates |
len == 0 |
Result |
Only finalized (e.g. Cancelled) |
empty |
true |
❌ Error returned (valid usage blocked) |
Only non-finalized (e.g. Available) |
[Available] |
false |
✅ No error (meaningless sort allowed) |
When a caller passes only non-finalized states and orders by finalized_at, every result row has finalized_at = NULL — the sort is meaningless. But no error is returned. The one case that should work (all finalized states) is incorrectly rejected.
Additionally, the error message prints currentNonFinalizedStates (the empty slice []) rather than the actual states being used, making the message uninformative.
Suggested fix
if len(currentNonFinalizedStates) == len(p.states) && len(p.states) > 0 {
return nil, fmt.Errorf("cannot order by finalized_at with only non-finalized state filters %+v",
currentNonFinalizedStates)
}
This fires when ALL states are non-finalized (the truly invalid case) and prints the actual problematic states in the error message.
Bug
JobListParams.toDBParams()injob_list_params.gohas an inverted guard when validating state filters forJobListOrderByFinalizedAt.Affected code (line ~244)
What's wrong
The comment says the guard is checking for "only non-finalized states" — but the condition
len(currentNonFinalizedStates) == 0is true when there are zero non-finalized states, meaning all states are finalized. That's actually the correct usage forJobListOrderByFinalizedAt.The inverted conditions:
currentNonFinalizedStateslen == 0Cancelled)Available)[Available]When a caller passes only non-finalized states and orders by
finalized_at, every result row hasfinalized_at = NULL— the sort is meaningless. But no error is returned. The one case that should work (all finalized states) is incorrectly rejected.Additionally, the error message prints
currentNonFinalizedStates(the empty slice[]) rather than the actual states being used, making the message uninformative.Suggested fix
This fires when ALL states are non-finalized (the truly invalid case) and prints the actual problematic states in the error message.