Skip to content

sort parameter: actual error codes (422, 200) don't match contract (400). Invalid sort silently fall back to ascending #389

Description

@MMilosz

Please describe your request
During tests, I found three issues related to pagination that need clarification on which behavior is intended vs should be fixed

Contract refs:

- `sort` - the criteria to use. Ordering is specified appending a comma and the keyword asc or desc to the criteria name (i.e. title,asc). Unknown sort criteria and/or ordering keyword produce an error response with Http Code `400`

RestContract/README.md

Lines 189 to 190 in 54bcdf6

### Pagination Error Codes
`400 Bad Request` - If an unknown sort criteria is requested, or a not valid ordering keyword is specified

Claims:

  • invalid sort field returns 400
  • invalid sort direction returns 400

Issue 1 - invalid sort fields returns 422, not 400

Base URL: https://sandbox.dspace.org/server/api/discover/search/objects

Parameter Return code
sort=dc.title,asc 200
sort=dc.date,asc 422
sort=doesnotexist,desc 422

Issue 2 - invalid sort direction returns 200, not 400

Base URL: https://sandbox.dspace.org/server/api/discover/search/objects

Parameter Return code
sort=dc.title,asc 200
sort=dc.title,dsc (desc typo) 200
sort=dc.title,doesnotexist 200

Issue 3 - the invalid direction is silently applied as ascending

Not covered by the contract

Base URL: https://sandbox.dspace.org/server/api/discover/search/objects

Tested via $ curl -s 'https://sandbox.dspace.org/server/api/discover/search/objects?sort=dc.title,desc' | jq -r '._embedded.searchResult._embedded.objects.[]._embedded.indexableObject.uuid' | head -3

Parameter Return body (shortened to first part of UUID)
sort=dc.title,asc 3329a278, fff7a10b, 51715dd3
sort=dc.title,desc bd254afc, ab19b0a2, cda7a628
sort=dc.title,dsc 3329a278, fff7a10b, 51715dd3
sort=dc.title,doesnotexist 3329a278, fff7a10b, 51715dd3

UUIDs for both dsc, doesnotexist match asc

Activity

  1. tdonohue commented on Oct 2, 2026

    @tdonohue
    Member

    @MMilosz : In my opinion, Issue 1 sounds like a small bug in the Rest Contract. Issue 2 and 3 could either be considered a minor bug or a contract bug. I think the current behavior is likely slightly wrong, as invalid params likely should result in an error code (either 400 or 422). But, those issues seems so very minor that I'm also OK with just documenting current behavior.

    I'd welcome other ideas/thoughts here from other developers though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions