Issue with trash_entity_query_alter

Created on 2 July 2025, 25 days ago

Problem/Motivation

I'm not entirely sure what the cause of this is but I'll try to explain what I'm experiencing.

We've been having a problem with being able to delete or edit nodes (which are members of a Group entity), where I get an error along the lines of:

Error: Call to a member function language() on null in Drupal\node\Controller\NodeController->revisionOverview() (line 150 of core/modules/node/src/Controller/NodeController.php).

After doing some debugging, in trash_entity_query_alter, we have this:

  if ($query->getMetaData('trash') === 'inactive') {
    $query->exists($deleted_key);
  }
  else {
    $query->notExists($deleted_key);
  }

The problem seems to occur when a record has a value in the deleted column of node_field_revision, for example this is from node_field_revision. The current revision for this node is 2068.

nid	vid	langcode	status	uid	title	created	changed	promote	sticky	default_langcode	revision_translation_affected	publish_on	unpublish_on	publish_state	unpublish_state	published_at	deleted
185	2065	en	0	68	to delete	1750082893	1750082907	0	0	1	1	NULL	NULL	NULL	NULL	NULL	NULL
185	2066	en	0	68	to delete	1750082893	1750082907	0	0	1	NULL	NULL	NULL	NULL	NULL	NULL	NULL
185	2067	en	0	68	to delete	1750082893	1750082914	0	0	1	1	NULL	NULL	NULL	NULL	NULL	NULL
185	2068	en	1	68	to delete	1750082893	1750082919	0	0	1	1	NULL	NULL	NULL	NULL	1750082919	NULL
185	2069	en	0	68	to delete	1750082893	1750082926	0	0	1	1	NULL	NULL	_none	_none	1750082919	NULL
185	2070	en	0	68	to delete	1750082893	1750082926	0	0	1	1	NULL	NULL	_none	_none	1750082919	1750082919

When trash_entity_query_alter applies this:

$query->notExists($deleted_key);

I get no rows returned and as such that node breaks - we can't edit or delete the node or view the revisions tab, although oddly we can view it.

With trash_entity_query_alter adding the deleted condition, we end up with a SQL query that looks like:

SELECT base_table.vid AS vid, base_table.nid AS nid
FROM node_revision AS base_table
LEFT OUTER JOIN node_revision AS base_table_2 
  ON base_table.nid = base_table_2.nid AND base_table.vid < base_table_2.vid
INNER JOIN node_field_data AS node_field_data 
  ON node_field_data.nid = base_table.nid
LEFT JOIN node_field_revision AS node_field_revision 
  ON node_field_revision.vid = base_table.vid
WHERE base_table_2.nid IS NULL
  AND node_field_data.nid = 185 
  AND node_field_revision.deleted IS NULL;

and that returns nothing, and as a result edit, delete and view revisions breaks.

I'd welcome any suggestions! I'm going to try and reproduce the issue on a clean site and check to see if it's just something specific to the build I'm working on.

🐛 Bug report
Status

Active

Version

3.0

Component

Code

Created by

🇬🇧United Kingdom welly

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

Comments & Activities

  • Issue created by @welly
  • 🇷🇴Romania amateescu

    I know that the Group module does some pretty advanced query altering, but Trash's entity query alter is just adding a regular field condition, so I'm a bit surprised there's a possible clash.

    Let me know whether you manage to reproduce this on a more vanilla site, otherwise I'll try to check it myself soon :)

Production build 0.71.5 2024