Uploaded image for project: 'DSpace'
  1. DSpace
  2. DS-3849

REST API items resource returns items in non-deterministic order

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Code Review Needed (View Workflow)
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 5.6, 5.7, 5.8, 6.0, 6.1, 6.2
    • Fix Version/s: 6.4
    • Component/s: REST API
    • Attachments:
      0
    • Comments:
      12
    • Documentation Status:
      Needed

      Description

      The DSpace 6.x (and possibly 5.x) REST API endpoint /collections/{collectionid}/items (and likely many other endpoints) returns items in an inconsistent order. The pagination of this resource is therefore error prone and can skip items, or return items on multiple pages.

      The issue lies in:

      public Iterator<Item> findArchivedByCollection(Context context, Collection collection, Integer limit, Integer offset)

      in ItemDAOImpl.java (line 226). The SQL query uses offset and limit parameters, but does not have an ORDER BY clause:

      select i from Item i join i.collections c WHERE :collection IN c AND i.inArchive=:in_archive 

      As noted on the [Postgres limit and offset documentation|https://www.postgresql.org/docs/8.0/static/queries-limit.html:]

       

      using different LIMIT/OFFSET values to select different subsets of a query result will give inconsistent results unless you enforce a predictable result ordering with ORDER BY. This is not a bug; it is an inherent consequence of the fact that SQL does not promise to deliver the results of a query in any particular order unless ORDER BY is used to constrain the order.

      I would propose that the query is changed to 

      select i from Item i join i.collections c WHERE :collection IN c AND i.inArchive=:in_archive order by i.uuid

        Attachments

          Activity

            People

            Assignee:
            bram Bram Luyten (Atmire)
            Reporter:
            andrewb Andrew Bennet
            Votes:
            2 Vote for this issue
            Watchers:
            8 Start watching this issue

              Dates

              Created:
              Updated: