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.
The new node is published and this only happens when view unpublished is enabled.
I updated to the latest version of dev rebuilt the permissions but no luck.
I debuged the code and in node_access() in node.module on the node_access part where the query $result is FALSE
any idea any help would be appreciated.
Comments
Comment #1
DuaelFrI just tested this issue on a clean simplytest instance and I am not able to reproduce it.
Comment #2
fox mulder CreditAttribution: fox mulder commentedI am not able to reproduce this problem on simplytest too, but I ran into this on a development site. My test user has access to create "A" type node, and has access to view any type unpublished node, but he/she is redirected after "A" type node creation to front page because node_access() returns FALSE.
I am using this debug code in the node_access() function:
It returns:
FROM
{node_access} node_access
WHERE (grant_view >= '1') AND( (nid = '623') OR (nid = '0') )AND(( (gid = '0') AND (realm = 'all') ))
LIMIT 1 OFFSET 0
FROM
{node_access} node_access
WHERE (grant_view >= '1') AND( (nid = '623') OR (nid = '0') )AND(( (gid = '0') AND (realm = 'all') )OR( (gid = '155') AND (realm = 'view_unpublished_author') )OR( (gid = '1') AND (realm = 'view_unpublished_content') ))
LIMIT 1 OFFSET 0
Result is 0 and the node author is returned to front page. But if I am copying the resulted SQL queries and I am using these queries in PHPMyadmin, than the result is 1.
It's magic
Used view_unpublished version: 7.x-1.2
Comment #3
joelstein CreditAttribution: joelstein commentedI experienced this, too, and I tracked it down to modules calling node_access() within hook_node_insert(), which results in a cached access result before node_save() has a chance to acquire the node access grants. For example, XML Sitemap does this, as well as Boost when used with Cache Expiration.
So if you are using a module which calls node_access() within hook_node_insert(), and you're using some access control modules, you will likely run into this bug. This is not the fault of the View Unpublished module. It's arguably a design problem within Drupal core, but regardless, it's something that needs to be fixed within the module invoking hook_node_insert().
Or you can simply reset the static node_access cache in your own module:
See the related issues to learn more.
Comment #4
fox mulder CreditAttribution: fox mulder commentedHi Joel! Thanks for your response.
Calling drupal_static_reset('node_access') in a custom hook_node_insert() implementation does not solves the problem for me :/
Comment #5
fox mulder CreditAttribution: fox mulder commentedThis works: