Problem/Motivation
When installing 1.7, I ran drush updb and immediately got integrity constraint violations.
When trying to rebuild access permissions from the status page (admin/reports/status/rebuild) I ran into the same problem.
This caused every page on the site to be blocked.
I updated composer audit to not block insecure and reverted to 1.6 and the issue went away.
Error:
[notice] Update completed: unpublished_node_permissions_update_8002
>
> In ExceptionHandler.php line 45:
>
> SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '5-0-
> all-und' for key 'PRIMARY': INSERT INTO "node_access" ("nid", "langcode", "
> fallback", "realm", "gid", "grant_view", "grant_update", "grant_delete") VA
> LUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeh
> older_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_pla
> ceholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7), (:db_inser
> t_placeholder_8, :db_insert_placeholder_9, :db_insert_placeholder_10, :db_i
> nsert_placeholder_11, :db_insert_placeholder_12, :db_insert_placeholder_13,
> :db_insert_placeholder_14, :db_insert_placeholder_15); Array
> (
> [:db_insert_placeholder_0] => 5
> [:db_insert_placeholder_1] => und
> [:db_insert_placeholder_2] => 1
> [:db_insert_placeholder_3] => all
> [:db_insert_placeholder_4] => 0
> [:db_insert_placeholder_5] => 1
> [:db_insert_placeholder_6] => 0
> [:db_insert_placeholder_7] => 0
> [:db_insert_placeholder_8] => 5
> [:db_insert_placeholder_9] => und
> [:db_insert_placeholder_10] => 1
> [:db_insert_placeholder_11] => all
> [:db_insert_placeholder_12] => 0
> [:db_insert_placeholder_13] => 1
> [:db_insert_placeholder_14] => 0
> [:db_insert_placeholder_15] => 0
> )
>
>
> In StatementWrapperIterator.php line 113:
>
> SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '5-0-
> all-und' for key 'PRIMARY'
>
>
Steps to reproduce
This might be tricky if it depends on certain conditions, but it started with installing 1.7 and running updb.
Proposed resolution
Identify the difference that would cause an integrity constraint violation and add something to stop this duplicate key being created.
Remaining tasks
Identify section of code
Issue fork unpublished_node_permissions-3579171
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 #2
edward.peters commentedI have exactly the same issue
Comment #3
vinaygawadeWe hit the same problem and traced it to update 8002:
```php
function unpublished_node_permissions_update_8002() {
node_access_rebuild(TRUE);
}
```
On our site, running this update triggered duplicate inserts into `node_access`, for example duplicate `(nid, gid, realm, langcode)` rows such as `all / 0 / en`, causing:
`SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry ... for key 'PRIMARY'`
This suggests that calling `node_access_rebuild(TRUE)` unconditionally inside `hook_update_N()` is not safe for all site configurations.
Suggested fix direction:
* remove the unconditional rebuild from `update_8002()`, and
* move this to a post-update / queued rebuild / manual rebuild step instead.
At minimum, the rebuild path needs a guard against duplicate grant insertion.
Mitigation for affected sites:
* revert to 1.6
* rerun cache/router rebuilds
* avoid running 8002 until there is a fix
Comment #5
vinaygawadeOpened MR for this issue. Removes duplicate `all / gid 0` grant causing integrity violations.
Would appreciate review.