Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
A user found this in XML sitemap. I use hook_node_save() to 'index' nodes as sitemap links and I call node_access('view', $node, drupal_anonymous_user()) in order to check if the node is accessible to anonymous user. The problem is that for new nodes, in node_save(), hook_node_save() is invoked before node_access_acquire_grants(), so the value of node_access() is not correct.
Comments
Comment #1
Dave ReidOriginal discovered issue was #690120: Cannot reliably check node_access from inside hook_node_save() with node grants
Comment #2
webflo CreditAttribution: webflo commentedRelated issue in Notifications #289211: Immediate notifications on nodes with node access fails.
Comment #3
joelstein CreditAttribution: joelstein commentedA workaround for anyone experiencing this is to simply reset the node_access cache in a custom module: