Keyword search in Views Table leads to "website encountered an error" screen

Created on 9 January 2018, almost 7 years ago
Updated 11 September 2024, 3 months ago

Problem/Motivation

I have created a View in Table format of a custom content type, displayed as a Page, and I've exposed the Search filter to allow keyword searching. The first unexpected thing about it is the filter displays on the page without my having to go to Place Block on the Blocks admin page. The other, more serious issue, is that when I perform a keyword search I
get a "The website has encountered an error. Please try again later" error page.This error gets logged:

Uncaught PHP Exception Drupal
\\Core
\\Database
\\DatabaseExceptionWrapper:
    "Exception in Database listing[database_listing]: SQLSTATE[42000]:
    Syntax error or access violation: 1055 Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column
    'library.node__field_resource_title.field_resource_title_value' which is not functionally dependent on columns in GROUP BY clause;
    this is incompatible with sql_mode=only_full_group_by:
    SELECT
    node_field_data.langcode AS node_field_data_langcode,
    node_field_data.nid AS nid, SUM(node_search_index.score * search_total.count) AS score,
    MIN(node_field_data.nid) AS nid_1\n
    FROM \n
    {node_field_data} node_field_data\n
    LEFT JOIN {search_index} node_search_index ON node_field_data.nid = node_search_index.sid
    AND (node_search_index.type = 'node_search' AND node_search_index.langcode = node_field_data.langcode)\n
    LEFT JOIN {search_total} search_total ON node_search_index.word = search_total.word\n
    INNER JOIN {search_dataset} node_search_dataset ON node_search_index.sid = node_search_dataset.sid
    AND (node_search_index.type = node_search_dataset.type AND node_search_index.langcode = node_search_dataset.langcode)\n
    LEFT JOIN {node__field_resource_title} node__field_resource_title ON node_field_data.nid = node__field_resource_title.entity_id
    AND node__field_resource_title.deleted = :views_join_condition_0\n
    WHERE (node_field_data.status = :db_condition_placeholder_1)
    AND (node_field_data.type
    IN (:db_condition_placeholder_2))
    AND ((node_search_index.type = :db_condition_placeholder_3)
    AND (node_search_dataset.data LIKE :db_condition_placeholder_4 ESCAPE '\\\\')
    AND (node_search_index.word = :db_condition_placeholder_5))\n
    GROUP BY node_search_index.sid, node_field_data_langcode, node_field_data.nid\n
    HAVING (COUNT(*) >= :node_search_index_keys)\n
    ORDER BY node__field_resource_title.field_resource_title_value ASC; Array\n
    (\n
      [:db_condition_placeholder_1] => 1\n
      [:db_condition_placeholder_2] => databases\n
      [:db_condition_placeholder_3] => node_search\n
      [:db_condition_placeholder_4] => % archival %\n
      [:db_condition_placeholder_5] => archival\n
      [:node_search_index_keys] => 1\n
      [:views_join_condition_0] => 0\n
    )\n"
    at [webroot]/core/modules/views/src/Plugin/views/query/Sql.php line 1489, referer: my-page-URL

I'm not certain this has been reported elsewhere; apologies if I've duplicated another issue.

---

Steps to reproduce

I can recreate the issue of Search Keywords exposed filter in a View causing a fatal error using the moderated_content view with the following steps.

Install Drupal
Enable Content Moderation and Workflows modules
Go to /admin/config/workflow/workflows/manage/editorial
Scroll to This workflow applies to:
Click the Select button to the right of Content types
Click All content types
Click Save in the modal
Click Save on the manage/editorial page
Go to /admin/structure/views/view/moderated_content/edit/moderated_content
In Filter criteria, click Add
In the Search field, type keywords
Click the checkbox next to Search Keywords
Click Add and configure filter criteria button
Click the checkbox next to Expose this filter to visitors, to allow them to change it
Click Apply
Scroll to the Preview of the view
Type a word in Search Keywords field
Click Filter
The Error prints on the screen

Here's the query.

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'data' in 'where clause':
  SELECT COUNT(*) AS "expression"
  FROM (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",
  MIN(users_field_data_node_field_revision.uid) AS "users_field_data_node_field_revision_uid",
  1 AS "expression"
  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 "users_field_data" "users_field_data_node_field_revision" ON node_field_revision.uid = users_field_data_node_field_revision.uid
  LEFT JOIN "node_field_revision" "node_field_revision2" ON node_field_revision.nid = node_field_revision2.nid
  AND (node_field_revision2.vid > node_field_revision.vid
  AND node_field_revision2.langcode = node_field_revision.langcode
  AND node_field_revision2.revision_translation_affected = :views_join_condition_3)
  LEFT JOIN "content_moderation_state_field_revision" "content_moderation_state" ON node_field_revision.vid = content_moderation_state.content_entity_revision_id
  AND (content_moderation_state.content_entity_type_id = :views_join_condition_4
  AND content_moderation_state.content_entity_id = node_field_revision.nid
  AND content_moderation_state.langcode = node_field_revision.langcode)
  INNER JOIN "node" "node" ON node_field_revision.nid = node.nid
  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_revision2"."nid" IS NULL)
  AND ("node_field_revision"."revision_translation_affected" = :db_condition_placeholder_0)
  AND (("node"."type" IN (:db_condition_placeholder_1, :db_condition_placeholder_2))
  AND (("content_moderation_state"."workflow" = :db_condition_placeholder_3)
  AND ("content_moderation_state"."moderation_state" <> :db_condition_placeholder_4)))
  AND (("node_field_data_node_field_revision_node_search_index"."type" = :db_condition_placeholder_5)
  AND (""."data" LIKE :db_condition_placeholder_6 ESCAPE '\\')
  AND ("node_field_data_node_field_revision_node_search_index"."word" = :db_condition_placeholder_7))
  GROUP BY node_field_data_node_field_revision_node_search_index.sid
  HAVING (COUNT(*) >= :node_search_index_keys)) "subquery";
  
Array (
    [:db_condition_placeholder_0] => 1
    [:db_condition_placeholder_1] => article
    [:db_condition_placeholder_2] => page
    [:db_condition_placeholder_3] => editorial
    [:db_condition_placeholder_4] => published
    [:db_condition_placeholder_5] => node_search
    [:db_condition_placeholder_6] => % my_keyword %
    [:db_condition_placeholder_7] => my_keyword
    [:node_search_index_keys] => 1
    [:views_join_condition_3] => 1
 )

You can see the query is failing at

AND (""."data" LIKE :db_condition_placeholder_6 ESCAPE '\\')

I think the error of exposed Search Keywords filter in Views are the same. Plain vanilla moderated_content view (with the bug) for Drupal 9.5.0-dev is attached to this issue.

🐛 Bug report
Status

Closed: cannot reproduce

Version

11.0 🔥

Component
Views 

Last updated 2 days ago

Created by

🇺🇸United States rvanderh1

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

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