SQL error when entity base table is unavailable in Views Query Alter

Created on 30 May 2025, 8 days ago

Problem/Motivation

The ViewsQueryAlter class attempts to join to a data table without checking if it exists, resulting in SQL errors with an empty table name. When processing entity revisions in views, the code tries to join to a data table identified by the relationship base, but if this table is null or doesn't exist, it creates an SQL query with an empty table name (LEFT JOIN "" "" ON...), causing a syntax error.

Steps to reproduce

  1. Create a view that includes content with revisions
  2. Have an entity type that doesn't properly define its relationship base
  3. Load the view, which triggers the ViewsQueryAlter class
  4. Observe the SQL error: Syntax error or access violation: 1103 Incorrect table name ''

The specific error shows an attempt to join to an empty table name:

LEFT JOIN "" "" ON node_revision.nid = .nid

Proposed resolution

Add a check to verify that the data table exists before attempting to create the join. This patch:

  1. Adds null coalescing to safely handle cases where relationship base is not defined
  2. Wraps the join creation in a conditional check to only proceed if a valid data table exists
  3. Prevents the SQL error by not attempting to join to non-existent tables

Remaining tasks

  1. Verify the patch works in different environments
  2. Add tests to cover this edge case
  3. Review and commit the patch

User interface changes

None. This is a backend fix that doesn't affect the UI.

API changes

None. This fix maintains the existing API while making it more robust.

Data model changes

None. This patch only affects query generation and doesn't modify any data structures.

🐛 Bug report
Status

Active

Version

3.0

Component

Code

Created by

🇳🇱Netherlands Remco Hoeneveld

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024