EntityQuery fails when combining revisions and node access.

Created on 1 November 2016, about 8 years ago
Updated 16 September 2024, 3 months ago

Problem/Motivation

Using entityQuery() with node as a base table in combination with node access grants and revisions results in a fatal error. Coming from #2781423: Skip access checking during update. , where this was thought to be a Paragraphs or View unpublished issue, but it appears to be a core bug.

Steps to reproduce

  • On a fresh D8 (Standard profile), enable a Node Access module (I used View Unpublished for this scenario).
  • Add an unpublished article
  • Rebuild node access permissions
  • As non-admin, run the following code:
    $entity_ids = \Drupal::entityQuery('node')
    ->condition('comment', NULL, 'IS NOT NULL')
    ->allRevisions()
    ->execute();
    

Executing this query will result in the exception below being thrown.

This is thought to be a core issue rather than View Unpublished since the hardcoded 'nid' column is added through node_query_node_access_alter() and NodeGrantDatabaseStorage::alterQuery()

Exception

The website encountered an unexpected error. Please try again later.

Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'node_revision__comment.nid' in 'where clause': SELECT base_table.vid AS vid, base_table.nid AS nid FROM {node_revision} base_table INNER JOIN {node_revision__comment} node_revision__comment ON node_revision__comment.revision_id = base_table.vid WHERE (node_revision__comment.comment_status IS NOT NULL) AND (EXISTS (SELECT na.nid AS nid FROM {node_access} na WHERE ((gid IN (:db_condition_placeholder_0)) AND (realm = :db_condition_placeholder_1)) AND (na.grant_view >= :db_condition_placeholder_2) AND ((node_revision__comment.nid = na.nid)))); Array ( [:db_condition_placeholder_0] => 0 [:db_condition_placeholder_1] => all [:db_condition_placeholder_2] => 1 ) in eval() (line 4 of modules/devel/src/Form/ExecutePHP.php(55) : eval()'d code).
Drupal\Core\Database\Statement->execute(Array, Array) (Line: 624)
Drupal\Core\Database\Connection->query('SELECT base_table.vid AS vid, base_table.nid AS nid
FROM 
{node_revision} base_table
INNER JOIN {node_revision__comment} node_revision__comment ON node_revision__comment.revision_id = base_table.vid
WHERE (node_revision__comment.comment_status IS NOT NULL) AND (EXISTS (SELECT na.nid AS nid
FROM 
{node_access} na
WHERE ((gid IN (:db_condition_placeholder_0)) AND (realm = :db_condition_placeholder_1)) AND (na.grant_view >= :db_condition_placeholder_2) AND ((node_revision__comment.nid = na.nid))))', Array, Array) (Line: 87)
Drupal\Core\Database\Driver\mysql\Connection->query('SELECT base_table.vid AS vid, base_table.nid AS nid
FROM 
{node_revision} base_table
INNER JOIN {node_revision__comment} node_revision__comment ON node_revision__comment.revision_id = base_table.vid
WHERE (node_revision__comment.comment_status IS NOT NULL) AND (EXISTS (SELECT na.nid AS nid
FROM 
{node_access} na
WHERE ((gid IN (:db_condition_placeholder_0)) AND (realm = :db_condition_placeholder_1)) AND (na.grant_view >= :db_condition_placeholder_2) AND ((node_revision__comment.nid = na.nid))))', Array, Array) (Line: 493)
Drupal\Core\Database\Query\Select->execute() (Line: 250)
Drupal\Core\Entity\Query\Sql\Query->result() (Line: 77)
Drupal\Core\Entity\Query\Sql\Query->execute() (Line: 4)
eval() (Line: 55)
Drupal\devel\Form\ExecutePHP->submitForm(Array, Object)
call_user_func_array(Array, Array) (Line: 111)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 51)
Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 585)
Drupal\Core\Form\FormBuilder->processForm('devel_execute_form', Array, Object) (Line: 314)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 74)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 574)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
call_user_func_array(Object, Array) (Line: 139)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 62)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 99)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 78)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 50)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 654)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

🐛 Bug report
Status

Postponed

Version

11.0 🔥

Component
Node system 

Last updated 4 days ago

No maintainer
Created by

🇧🇪Belgium mr.baileys 🇧🇪 (Ghent)

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.

  • The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

    Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

  • Status changed to Postponed 3 months ago
  • The "Node Access module" is not fully compatible with Drupal 10, let alone Drupal 11.x. I'm unable to reproduce this issue for now.

Production build 0.71.5 2024