Problem/Motivation

ViewsQueryAlter adds a condition for the "deleted" field, but assumes the entity's base table is always present. This leads to a broken query for Views based on revisions.

Steps to reproduce

Have Trash and Views enabled.
Enable Trash module for Nodes.
Create a new View based on Node Revision and save it.
The view will crash with a broken query due to the "node_field_data" table not being included in the query.

Proposed resolution

Join in the base table before adding the condition.

CommentFileSizeAuthor
#4 3393095-4.patch8.33 KBamateescu

Issue fork trash-3393095

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

TwoD created an issue. See original summary.

twod’s picture

Status: Active » Needs review
Issue tags: -Trash crashes revision based Views queries. +Needs tests

Initial attempt at fixing this. My Views no longer crash and by default they only include non-deleted entities.

I'm not very used to altering Views queries so could use some help making sure this is correct.
I noted Trash does not modify entity queries if you tell them to look at all revisions, but I think it makes more sense to actually do this for Views.

This could use some tests with revision based Views as well.

amateescu’s picture

StatusFileSize
new8.33 KB

I've been going back and forth through this code for the past week, and in addition to the problem described in the issue summary, it also doesn't handle entity references very well: a filter on the deleted field might be added to the view on either the base (data) table or the revision (data) table of the referenced entity type, and we're currently not checking for the second case.

Here's a patch based on the MR from #2 which fixes both problems and cleans up the class a little. I've done quite a bit of manual testing, but I'd love at least another confirmation if you have the time @TwoD.

I noted Trash does not modify entity queries if you tell them to look at all revisions, but I think it makes more sense to actually do this for Views.

I agree, and it makes sense to do the same for entity queries as well, but we'll need another issue for that.

amateescu credited josebc.

amateescu credited kala4ek.

amateescu’s picture

amateescu’s picture

Title: Trash breaks revision based View queries » Trash breaks revision-based views and relation queries

  • amateescu committed 66d62ca4 on 3.x authored by TwoD
    Issue #3393095 by TwoD, amateescu, josebc, kala4ek: Trash breaks...
amateescu’s picture

Status: Needs review » Fixed

Tested on a few more views and I'm comfortable enough with those changes, so committed and pushed to 3.x, thanks everyone!

Status: Fixed » Closed (fixed)

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