Problem/Motivation

Whenever a user call user_role_grant_permissions if the permission is not valid (not being implemented by any module) Drupal shouldn't try to execute the db_merge since it will incur in a database error.

Proposed resolution

The function already load all permissions by using $modules = user_permission_get_modules();
We should check if $modules[$name] is valid before trying to execute db_merge.

Remaining tasks

Patch provided, needs review.

User interface changes

None

API changes

None

Comments

handrus’s picture

Patch to check if permission exists before trying to merge to db.

sebas5384’s picture

Nice patch! simple and clean :)

alexpott’s picture

Status: Needs review » Closed (outdated)

FWIW Drupal 10 will throw an exception when a permission does not exist and you save a role. I don't think this change could be made in Drupal 7 because it could break things.