Duplicates on Table format view using pagination and sorting on a date field that has duplicate values for multiple rows

Created on 12 December 2022, about 2 years ago
Updated 9 November 2023, about 1 year ago

Problem/Motivation

If sort criteria has same value, you might see duplicates on different pages.

Steps to reproduce

 - Create 50 nodes, articles will do. Use the devel module.
 - update title to match node entity id (this will help with seeing duplicates) and update created date for all nodes to the same value (unix timestamp).
 - create a table (format) view, with title, and created date, set pages to 20 items. Sort by created date.
 - complete the view by adding a path and saving it.
 
When you visit the path, and navigate to another page, you might see duplicates displayed, like node 10 is displayed on page 1 and page 2.

This might be paginator issue and/or database driver, how database rows are returned to drupal and then applied sort.

This may not be specific to Table format of views.

To answer the question "how would you end up with the same created date timestamp on your entities anyway?" is migration. In my particular case, all redirects migrations end up with the same created date (timestamp).

Adding secondary default sort, using primary key. So for nodes, it would be nid as a secondary sort. My workaround is, using "AddOrderBy" in hook_views_query_alter and adding the primary key field. 

Proposed resolution

πŸ› Bug report
Status

Active

Version

9.5

Component
ViewsΒ  β†’

Last updated about 11 hours ago

Created by

πŸ‡¨πŸ‡¦Canada igorbiki

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡«πŸ‡·France solene_ggd

    Hello, I had the same issue on an unformatted view, I don't think it is specific to the table format. Some entities showed up twice on page 1 and page 2 sort criteria are the same. I fixed it by adding sort on entity ID.

  • I also encounter this issue. My case is:

    There are two different nodes (Node1 and Node2) which has a custom field 'Event date' of type Date range;
    Thees nodes has the same value for 'Event date'; like

    "field_event_date" => array:1 [β–Ό
          "x-default" => array:1 [β–Ό
            0 => array:2 [β–Ό
              "value" => "2024-08-30T09:00:00"
              "end_value" => "2024-08-30T12:00:00"
            ]
          ]

    The view has sorting by two criteria: 1) Content: Event date:end_value (asc); 2) Content: Event date (asc);
    The view has a pagination;
    There are some other nodes on the results: some of them before Node1 and Node2, some of them after;
    When Node1 is the last node on the view page, then on the next page the same node is the first. Node2 is never shown;

    This could be solved by adding an adding sort by entity ID

  • πŸ‡ΊπŸ‡ΈUnited States joshua.boltz

    I have just run into this exact issue and it was driving me crazy. I thought it was the way I was rendering the View programmatically, but turns out the culprit was in the View itself.

    I had the same symptoms as outlined in this issue, that when using pagination, some items were missing and some items were duplicated.

    I had noticed that the content that was being queried in the View had 10 our of 15 of them had the exact same "Created/authored on" date timestamps. These same timestamps were throwing off the sort that was set, which was to sort them by the "Created/authored on" field.

    The quick solution for us was to add a secondary sort to the View (Title ASC), so that if any of the items (10 in our case) has the same values, that the group of those items would then be sorted using the Title. This solved our issue.

    The other option, that we didn't go down, was to manually or programmatically update these nodes to adjust their "Created/authored on" date timestamps so the sort and pagination could work as expected.

    Just in case this helps anyone else in a similar situation.

Production build 0.71.5 2024