- π¦πΊAustralia acbramley
Confirmed the issue is still reproducible on Drupal 10.1.x
- Status changed to Needs review
over 1 year ago 9:56pm 30 March 2023 The last submitted patch, 13: 3076680-13.patch, failed testing. View results β
An invalid query is produced on a node revisions view when adding a relationship to the actual content and adding an exposed filter on Search keywords
Install the standard profile on Drupal 10.1.x
Import the attached views config (making sure to rename it to remove the underscore from views.view_
Visit admin/structure/views/view/test_revisions
Submit the filter in the view preview.
A view that is based on node revisions will create an incorrect query if a keyword search filter is included. I've attached the simplest of views from a new drupal 8.7 install to reproduce this. In trying to debug this on a client site I stepped through the search views plugin but it seems like the error in creating table aliases happens earlier which is why I assume the node module.
Here is a base query that works:
SELECT "node_field_revision"."vid" AS "vid", "node_field_data_node_field_revision"."nid" AS "node_field_data_node_field_revision_nid"
FROM
{node_field_revision} "node_field_revision"
LEFT JOIN {node_field_data} "node_field_data_node_field_revision" ON node_field_revision.nid = node_field_data_node_field_revision.nid AND node_field_data_node_field_revision.langcode = node_field_revision.langcode
WHERE "node_field_revision"."status" = '1'
Here's the query that throws an exception when adding a search word of "test":
SELECT SUM(node_field_data_node_field_revision_node_search_index.score * search_total.count) AS "score", MIN(node_field_revision.vid) AS "vid", MIN(node_field_data_node_field_revision.nid) AS "node_field_data_node_field_revision_nid"
FROM
{node_field_revision} "node_field_revision"
LEFT JOIN {node_field_data} "node_field_data_node_field_revision" ON node_field_revision.nid = node_field_data_node_field_revision.nid AND node_field_data_node_field_revision.langcode = node_field_revision.langcode
LEFT JOIN {search_index} "node_field_data_node_field_revision_node_search_index" ON node_field_data_node_field_revision.nid = node_field_data_node_field_revision_node_search_index.sid AND (node_search_index.type = 'node_search' AND node_search_index.langcode = node_field_data.langcode)
LEFT JOIN {search_total} "search_total" ON node_field_data_node_field_revision_node_search_index.word = search_total.word
WHERE ("node_field_revision"."status" = '1') AND (("node_field_data_node_field_revision_node_search_index"."type" = 'node_search') AND (""."data" LIKE '% test %' ESCAPE '\\') AND ("node_field_data_node_field_revision_node_search_index"."word" = 'test'))
GROUP BY "node_field_data_node_field_revision_node_search_index"."sid"
HAVING (COUNT(*) >= '1')
The '.data' in the third WHERE condition should get replaced by something like 'node_field_data_node_field_revision_node_search_dataset.data' but the search plugin never gets passed any table aliases to use for replacements. line 175 of core/modules/search/src/Plugin/views/filter/Search.php
$search_dataset = $this->query->addTable('node_search_dataset');
returns FALSE:
I was able to alter the query just for my view and that's basically what I had to do. I'm also hoping to figure out where this needs to be patched but I haven't figured that out myself yet.
Needs review
10.1 β¨
The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.
Not all content is available!
It's likely this issue predates Contrib.social: some issue and comment data are missing.
Confirmed the issue is still reproducible on Drupal 10.1.x
The last submitted patch, 13: 3076680-13.patch, failed testing. View results β