When a distribution contains a user permission feature where the module defining the permission hasn't been enabled yet, the install process can fail with the error "SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'module' cannot be null"

Not only does this crash the installer, but the above error message doesn't provide any help in determining which permission/module is causing the problem.

The patch included in the next comment fixes these issues. If the module is empty, an error message is displayed indicating which permission is a problem, and the permission is skipped in installation allowing it to continue.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mpotter’s picture

mpotter’s picture

Status: Active » Needs review
hefox’s picture

seanr’s picture

This seems like a much better solution than the other one. It's nice and clean and it presents useful feedback to the user.

Pancho’s picture

Category: feature » bug

Not postponing for now, but we might want to wait and see whether Core leaves responsibility on the caller's side or takes it over to callee's side, see: #737816: user_role_grant_permissions() throws PDOException when used with non-existent permissions (e.g. a permission for a disabled/uninstalled module)...

hefox’s picture

Would it be utterly horrid to set the module to 'features'? (either by creating a copy of user permission function that fills in 'features' instead, or via defining the missing perms in hook_permission somehow. Just occurred to me, not sure how dumb.

Module is so the perm can be uninstalled correctly, and since features is handling adding this permission, it doesn't seem so bad to set module to 'features'. Actually, if features set all the permissions it adds to features, that's one way to tell features added the mapping vs. something else. hm.

MiroslavBanov’s picture

Status: Needs review » Needs work
drupal_set_message(t('Module for permission !name not found.', array('!name' => $perm)), 'error');

This is not quite as informative as I would like. If we are doing a feature revert, this is fine, but if we are installing a profile with 500 modules, then this error doesn't tell much.
A better one would be:

drupal_set_message(t('Error in "!function". No module was found that defines permission "!permission". Cannot grant or revoke permission.', array('!function' => __FUNCTION__, '!permission' => $perm)), 'error');
hefox’s picture

Status: Needs work » Needs review

I have no opinion whether this error message could be improved but
1) There's only one place/function using this error message tmk
2) I cannot think of anywhere else that adds in the function name like this.

Adding information that would not be apparent by looking at user_permission_features_rebuild could be useful, e.g. "defined by module !module" for example. or "during features rebuild of !module"

MiroslavBanov’s picture

OK, so the !function part is not needed because you would just search in the code.

"defined by module !module" is a bit ambiguous, because there is the module which has the feature component, but each exported permission stores the module which defines the permission at the moment it was exported. But then it is not important what that module is, because all that is required is that at least one module (no matter which) defines that permission at the moment that the feature is being rebuilt. So, using your second suggestion, how about this:
Error in features rebuild of !module. No module defines permission "!permission".

Not too lengthy and gives some useful information.

ndobromirov’s picture

Hello,

The patch in comment 1 breaks the profile installation under AEGIR environment, when the error is experienced.
I am adding a patch with lower error level -> warning.
Also added the discussed changes in the error message.
Changed the if() {....} else { .. } control flow to if ( ) { ... continue; } ... , seems better with less offsets.
The strange message generation is to keep the 80 characters row limit.

Best regards,
Nikolay Dobromirov

hefox’s picture

Status: Needs review » Needs work

T needs to have text inside it for parsing to work correctly when making those translatable files

ndobromirov’s picture

Changed the T function parameter to be a string literal.

hefox’s picture

Status: Needs work » Needs review
hefox’s picture

Hm, instead of error, perhaps Issue?

I've seen with some jenkins tasks saying error will mark the build as failed ('warnings' are fine).

mpotter’s picture

Status: Needs review » Fixed

Rerolled this because of the changes from term id names and added it to commit 787ff92. Also changed it from "Error in features" to "Warning in features" to match the severity level.

bleen’s picture

Status: Fixed » Active

the user_permission_get_modules() function is still returning an array in the form " [edit terms in 10] => taxonomy" and so on revert all my features that define a permission are throwing this error

bleen’s picture

Status: Active » Fixed

this was already reported here: https://drupal.org/node/1722524 so I'm closing again

Status: Fixed » Closed (fixed)

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