Views shows all results instead of topmost

Created on 12 January 2023, almost 2 years ago
Updated 13 September 2024, 2 months ago

Problem/Motivation

After upgrading to 9.5.1, the views on my site are out of whack.

Structure, working fine until 9.5.1:
A view of a list of IDs, sorted descending, showing only the topmost result, adding 1 using twig in a global text field. This mimicked "show next ID to use". F.e.: There are records with ID 917, 918, 920 in the database. The view lists only the first result (920), adds 1 and displays "next ID to use: 921.

This still works fine with 9.5.1, but when this views-block gets called in a global views reference in the footer line of another view, ALL existing IDs get displayed, with one added to the value.

This is confusing for my users, to say the least, and I have yet to find a workaround for this sick behaviour. Views "max value" didn't work for me in the past, maybe it's the way to go now.

Steps to reproduce

It's easy. Just try it for yourself.

Additional information

With 9.5.0, the very view showed an error whenever called from the menu. The error read

Warning: Trying to access array offset on value of type null in Drupal\views\Plugin\views\display\EntityReference->query() (Zeile 195 in /var/www/web2/htdocs/9/web/core/modules/views/src/Plugin/views/display/EntityReference.php)

When the page was refreshed, the error vanished. This behaviour got solved with 9.5.1, but now the single "next ID" shows as a list.

πŸ› Bug report
Status

Postponed: needs info

Version

11.0 πŸ”₯

Component
ViewsΒ  β†’

Last updated about 9 hours ago

Created by

πŸ‡¦πŸ‡ΉAustria nofue

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.

  • πŸ‡¦πŸ‡ΉAustria nofue

    First: no, I don't have any custom code except some twig within the view I'm using. I'm not trying any array offset whatsoever, I'm just using a view which works in preview as an embedded view in the footer of another view.

    The issue is completely unrelated to the kind of view. I get the same odd result with page views as well as block views or entity reference views.

    To repeat myself:
    I created a view vrh_pj_nextid
    which is embedded in another views footer section
    to display the next ID a project should be given.

    That view vrh_pj_next id is an entity reference list with a hidden field, pj-id, which gets used in a global text field in a twig statement to increment the number returned by one:

    {% set next = field_pj_id | trim %}
    {{ next+1 }}

    The number of results to be displayed is limited to one, and the sorting is set to pj_id, descending.

    In the preview, this view shows exactly one result value, the highest pj_id in the database + 1
    The views using that query in the footer showed exactly the same result: ONE result, just ONE -- today it's 1253

    Now, since upgrading to 9.5.1, all the views using that view vrh_pj_nextid
    show ALL the values in the database +1. A list, instead of just one value, as restricted in the basic vrh_pj_nextid view. Today, this very list shows
    1253 1252 1251 1250 … beneath the view which shows single items with an id of pj_id

    As a workaround, I created a simple drop down showing the values of the vrh_pj_nextid view, and sure enough, the drop down is also populated with all the values in the database +1 instead only the highest value + 1.

    I also tried Aggregation=ON,

    What else shall I provide?

    It's as simple like this:
    Create some content type holding a single integer number.
    Populate that view with some records: 1 - 2 - 5 - 9 - 19 - 2002 should suffice
    create a view for this content type, only showing that very field, ordered descending
    LIMIT this view to a single result to a single value in Page Navigation OR use aggregation - MAX to get the highest value so far in this field

    Make sure you see exactly ONE value as a result, the highest value (2002 in my example) in the database.

    Now use this view as an attached view in the footer of another view.
    What do you see?

    I get a list of all the values in the database, 1259192002

    And this behaviour begun with 9.5.1, and it's still in 9.5.2

  • πŸ‡¦πŸ‡ΉAustria nofue

    Or, let's put the issue the other way around:

    How to get the highest value of a field of given content type as a result in views, and showing that very result beneath another view.

    The option which should do it, is using aggregation and using the MAX function with the field you want to see the maximum from.
    I did this, and it works nicely.
    BUT once I put this view into another view's footer as an attached view, I get the whole list of values.
    This also happened with 9.5.0, iirc.

    I came up with a workaround, using a regular query, sorting results descending, and showing only the topmost result using the page navigation. This worked in the stand alone case as in the embedded case, hence I used it from 9.5.0 on. But with 9.5.1 BOTH options are broken …

    See attached screen shots. vrh-pj-nextid.jpg shows what is expected (and as it works). vrh-pj-list.jpg shows how the result looks once the vrh-pj-nextid view is attached to the footer of vrh-pj-list since D9.5.1

  • πŸ‡¦πŸ‡ΉAustria nofue

    After some more hours on this oddity, I came up with no solution, but one more finding :)

    It occurred to me that "page navigation" actually means PAGE navigation since D9.5.1.
    I.e. entering "1" for the number of allowed rows in the result, only 1 line (in my case the next ID to use) would be shown, if, and only if the view would be a page view.

    However, when duplicating my entity reference view to a page view and calling that view using its URL, the same odd "all lines of the database" behaviour could be spotted.

    To add to the list, the following error occurred today, after running some composer upgrade -W

    Warning: Undefined array key "in" in Drupal\views\Plugin\views\filter\NumericFilter->adminSummary() (line 389 of core/modules/views/src/Plugin/views/filter/NumericFilter.php).

    I can't make much sense from this, but I hope some coder gets an idea as what's going on here.

  • Hi,
    I got the exactly same issue as nofue ! It's very annoying because I don't find any workaround.
    I posted an issue on "Views field view" module, but no more answer. https://www.drupal.org/project/views_field_view/issues/3352876 πŸ› Paging : item limitation is not propagate Active
    It seems that the last update on this module was not involved (I tried a downgrade).

    During my investigation, I saw that final view (that embedded the first one) receive an array with all results, and not just the page 1 as expected. So logically the 2nd view display the view field with all the items. It probably confirme that the change in more related to the core than to the views field view module.

    The way how the paging / display limitation may have changed and it's not made at the query level but on render level. Has someone knowledges on that? It's not easy to investigate more into this complex module ^^

    Thanks for any help
    Cyril

  • πŸ‡¦πŸ‡ΊAustralia pameeela

    I can appreciate how frustrating this issue is, but it's still not clear how to reproduce it. There is a lot of info provided, but the best way to get assistance is to provide *very* specific steps to reproduce β†’ the issue, starting with "Install Drupal" and listing the exact view configuration required.

    I created a view vrh_pj_nextid
    which is embedded in another views footer section
    to display the next ID a project should be given.

    It may seem obvious to you what this means but I honestly have no idea.

    If more info isn't provided within 3 months, this issue may be closed.

Production build 0.71.5 2024