Views relationships are missing deleted check, allowing deleted content to show in views listings

Created on 30 September 2025, 28 days ago

Problem/Motivation

Views relationships (joins) are missing the trash deleted check. This allows deleted content to show in views listings.

The current views query alter logic only adds the deleted check on the base table, but it should also do it for relationships.

Steps to reproduce

  1. Content type "Article" with an entity reference field "Related Articles" which allows referencing other article nodes.
  2. Trash enabled for Article.
  3. Create 3 articles: Article A (no references), Article B (references Article A), and Article C (references Article C)
  4. Create a view that will show a list of articles that reference the article being viewed. This requires a contextual filter for Content ID (the article being viewed), and a relationship "Content using field_related_articles". Then for fields to display, we display "Content: Title" and use the relationship.
  5. Delete (move to trash) Article B
  6. Using views preview, put in the ID of Article A for the contextual filter

Expectation: Only Article C is listed.
Reality: Article B and Article C are listed, even though Article B is in the trash.

This is the query produced:

SELECT node_field_data.created AS node_field_data_created, node_field_data.nid AS nid, field_related_articles_node_field_data.nid AS field_related_articles_node_field_data_nid
FROM node_field_data node_field_data
INNER JOIN node__field_related_articles node__field_related_articles ON node_field_data.nid = node__field_related_articles.field_related_articles_target_id AND node__field_related_articles.deleted = '0'
INNER JOIN node_field_data field_related_articles_node_field_data ON node__field_related_articles.entity_id = field_related_articles_node_field_data.nid
WHERE (((node_field_data.nid = '4')) AND (node_field_data.deleted IS NULL)) AND (node_field_data.status = '1')
ORDER BY node_field_data_created DESC
LIMIT 5 OFFSET 0

This is what it should be to exclude the deleted articles in the join:

SELECT node_field_data.created AS node_field_data_created, node_field_data.nid AS nid, field_related_articles_node_field_data.nid AS field_related_articles_node_field_data_nid
FROM node_field_data node_field_data
INNER JOIN node__field_related_articles node__field_related_articles ON node_field_data.nid = node__field_related_articles.field_related_articles_target_id AND node__field_related_articles.deleted = '0'
INNER JOIN node_field_data field_related_articles_node_field_data ON node__field_related_articles.entity_id = field_related_articles_node_field_data.nid AND field_related_articles_node_field_data.deleted IS NULL
WHERE (((node_field_data.nid = '4')) AND (node_field_data.deleted IS NULL)) AND (node_field_data.status = '1')
ORDER BY node_field_data_created DESC
LIMIT 5 OFFSET 0

Proposed resolution

I'm not very familiar with views query alters, but I think we need to somehow alter the join to add the additional condition for deleted is NULL check.

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Active

Version

3.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States bkosborne New Jersey, USA

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

Merge Requests

Comments & Activities

Not all content is available!

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

Production build 0.71.5 2024