A bunch of our sites (we run a lot on the same codebase) were intermittently throwing an exception on module enable and disable:

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'anonymous user' for key 'name': INSERT INTO {role} (name, weight) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1); Array ( [:db_insert_placeholder_0] => anonymous user [:db_insert_placeholder_1] => 5 ) in drupal_write_record() (line 7036 of /mnt/www/html/cam8001/docroot/includes/common.inc).

I tracked this down to secure_permissions_build_roles(). In some cases, it seems like secure_permissions thinks that some roles are not yet created, when they are. I'm not sure what causes this, as when I run debugging code in devel/php, 'secure_permissions_get_roles()' and 'user_roles()' return exactly the same thing.

This band-aid solution stops the exceptions being thrown, and will only insert roles if they don't already exist in the user_roles table.

Members fund testing for the Drupal project. Drupal Association Learn more


Cameron Tod’s picture

Version: 7.x-1.x-dev » 7.x-1.5
Vincenzo’s picture

I came across this myself and am testing this patch right now.
If all good, I'll apply the patch to the HEAD dev.

bellesmanieres’s picture

I experienced the same pb. In my case pb came from enabling i18n at some point. Given that secure_permissions fetches roles using user_roles, it ends up with translated role name, which don't match those in db. One solution would probably be to gather the untranslated role names instead everywhere secure_permissions uses user_roles, as the provided patch fixes the db error, but (in my case at least) prevented auth and anon permissions from being rebuilt correctly.
Will give it a try and provide a patch soon…

bellesmanieres’s picture

Version: 7.x-1.5 » 7.x-1.x-dev
1.89 KB

Patch attached. Got a feeling it might also fix #1772484: On sites with a non-English default language, secure permissions cannot be rebuilt
[edit]I mean the multilanguage related issue part of #1772484: On sites with a non-English default language, secure permissions cannot be rebuilt. The patch itself that removes the return if no perms are defined for a role still is valid[/edit]

bellesmanieres’s picture

Issue summary: View changes

fixed grammar

danquah’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

Just ran into this issue, applied the patch and verified that it works as advertised with a debugger.

kreynen’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.