Trash breaks when views data has a null value

Created on 4 December 2023, over 1 year ago
Updated 7 February 2024, about 1 year ago

Problem/Motivation

Trash breaks when theres is a null value while fetching the views data in ViewsQueryAlter.php in line

$table_data = $this->viewsData->get($info['base']);

Steps to reproduce

Need a content page that fetches null value in views data. Tested and found the bug in the system with a custom module that shows hierarchy (e.g tree module) elments inside a content. The block doesn't work in edit mode. And the page crashes when try to load the node with the fololwing error log

InvalidArgumentException: A valid cache entry key is required. Use getAll() to get all table data. in Drupal\views\ViewsData->get() (line 140 of core\modules\views\src\ViewsData.php).

Proposed resolution

A simple condition can be added that handles the null value in the ViewsQueryAlter.php

if (!is_null($info['base'])) {
$table_data = $this->viewsData->get($info['base']);
}
else {
$table_data = [];
}

🐛 Bug report
Status

Fixed

Version

3.0

Component

Code

Created by

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

Comments & Activities

  • Issue created by @TH94
  • 🇮🇳India Akhil Babu Chengannur

    I was trying to test the patch, but was unable to reproduce the issue based on the provided issue description. Could you please provide clearer steps to reproduce the error?

  • @Akhil Babu , So I am not certain about the process of reproducing the error. The current issue is occuring when I have any taxonomy values (/conteexual filters in view) set in a certain view which contains a null value.

  • 🇺🇸United States mediabounds

    I encountered this issue and determined it's caused by a view using a relationship that has no base table; the taxonomy_index_tid_depth view argument from core is a good example.

    Best I can tell, in this scenario, we should just skip over that relationship since the module wouldn't know how to alter the query for it anyway.

    The attached patch avoids attempting to alter relationship queries if they have no base table.

  • 🇺🇸United States SocialNicheGuru

    Can it be written to log so that it can be followed up?

  • 🇺🇸United States mediabounds

    If we're talking about the same issue--the lack of a base table on a relationship is not a bug. It is the expected behavior of some relationship types in Views. The Trash module needs a change like the patch in #4 to handle scenarios when the relationship has no base table.

  • Status changed to Fixed about 1 year ago
  • 🇷🇴Romania amateescu

    Committed the patch from #4 to 3.x, thanks!

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024