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
- Create a view that includes content with revisions
- Have an entity type that doesn't properly define its relationship base
- Load the view, which triggers the ViewsQueryAlter class
- 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:
- Adds null coalescing to safely handle cases where relationship base is not defined
- Wraps the join creation in a conditional check to only proceed if a valid data table exists
- Prevents the SQL error by not attempting to join to non-existent tables
Remaining tasks
- Verify the patch works in different environments
- Add tests to cover this edge case
- 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.
| Comment | File | Size | Author |
|---|---|---|---|
| check-if-revision-table-exists.patch | 1.47 KB | remco hoeneveld |
Issue fork trash-3527404
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
Comment #4
amateescu commentedThanks for opening this issue. While I agree that this case needs to be handled better, I don't agree with the AI that generated the solution (and the issue summary by the looks of it), and I think we need to throw a helpful exception in order to make the developer aware of the problem.
Comment #6
amateescu commentedMerged into 3.x.
Comment #7
remco hoeneveld commented`Haha AI did help me write the above summary, but it did not write the patch ;)
Thank you for making the needed changes!