Issue #3579171: Fix duplicate node_access records during rebuild

Closes #3579171

Proposed fix for duplicate node_access entries during update 8002

This MR provides a fix for the integrity constraint violation reported when running:

unpublished_node_permissions_update_8002()

Problem

During node_access_rebuild(), duplicate rows were being inserted into the node_access table, causing errors like:

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '2-0-all-en' for key 'PRIMARY'

This happens because the module was adding the default published-node access grant:

  • realm = all
  • gid = 0

for published translations inside hook_node_access_records(), while Drupal core already creates this record.

Solution

This patch:

  1. Removes the redundant else block that adds the core all / gid 0 grant.
  2. Ensures the module only returns access grants for unpublished nodes (its intended responsibility).
  3. Adds a small deduplication helper as a defensive safeguard against duplicate grant rows.

Result

  • drush updb completes successfully
  • node_access_rebuild() runs without errors
  • No duplicate entries are inserted
  • Existing functionality for unpublished node access remains unchanged

Notes

Tested on Drupal 10.6.x with module version 8.x-1.7.

Merge request reports

Loading