Comments

mpotter’s picture

I'm getting this also. Specifically, the error is:

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'module' cannot [error]
be null: INSERT INTO {role_permission} (rid, permission, module) VALUES (:db_insert_placeholder_0,
:db_insert_placeholder_1, :db_insert_placeholder_2); Array
(
[:db_insert_placeholder_0] => 3
[:db_insert_placeholder_1] => use text format panopoly_html_text
[:db_insert_placeholder_2] =>
)
in user_role_grant_permissions() (line 3079 of
/opt/development/mpotter/openatrium-7.x-2.x-dev/modules/user/user.module).

In this case the "use text format panopoly_html_text" permission is being installed by the panopoly_wysiwyg module using defaultconfig. The defaultconfig file looks like this:

// Exported permission: use text format panopoly_html_text.
$permissions['use text format panopoly_html_text'] = array(
'name' => 'use text format panopoly_html_text',
'roles' => array(
'administrator' => 'administrator',
'editor' => 'editor',
),
'module' => 'filter',
);

So we can see that the Module is defined, but somehow isn't making it into the user_role_grant_permissions() callback.

Looking at the code in defaultconfig.module, it's the defaultconfig_component_rebuild($component, $module = FALSE) function that is calling user_role_grant_permissions() at the end (via $component['rebuild callback']) via defaultconfig_component_rebuild_permissions().

The defaultconfig_component_rebuild_permissions() function largely came from Features (user_permission_features_rebuild), but in Features, relevant to the #1975512: Installing user permission feature when module not available crashes build issue, we added a check for an invalid module.

Now, while we could add a similar check for a valid module here, in this case the module in question is the "filter" module, which is properly listed in the dependencies of the profile. So the real question is: why isn't "filter" enabled and available as a valid module.

Note that this error comes up when testing a profile installation using the drush "site-install" command. So my guess is that some cache isn't getting refreshed somewhere so the module list is not updated.

Rather than just patching the error (which would defeat the purpose of defaultconfig actually setting the desired permission), I will explore in more detail to see if there is just a static cache clear needed somewhere. So stay tuned.

mpotter’s picture

So here's the core problem:

The user_role_grant_permissions() function in Drupal gets the module name from the user_permission_get_modules() function. The actual "module" key in the feature export is ignored.

The user_permission_get_modules() function gets the array of permissions and modules by invoking hook_permission for enabled modules. In this case, the panopoly_wysiwyg module has not yet been enabled, so it isn't in the list of permissions/modules returned by user_permission_get_modules().

So how did this ever work? Seems like by definition the module using defaultconfig won't be enabled before it tries to add permissions.

hefox’s picture

modules are enabled during hook_modules_enabled, which are when defaultconfig works.

However, is it running before or after features, and is the filter panopoly_html_text defined via features or defaultconfig?

mpotter’s picture

OK, I found the problem. If the same feature includes both the defaultconfig for a filter permission *and* the filter itself, the defaultconfig runs before the filter is created by Features.

Looks like there was already some code to try and handle this:

    // Make sure we have all permissions by rebuilding filters and rebuild
    // node types.
    node_types_rebuild();
    if (!empty($module)) {
      module_load_include('inc', 'features', 'features.export');
      filter_features_rebuild($module);
    }

The problem with this is that filter_features_rebuild doesn't create the filters because the filter feature hasn't been imported yet. Specifically, Features is not including the module.features.filter.inc file that defines the default_hook needed to rebuild the filter.

The patch is simple. It just adds:

module_load_include('inc', $module, "$module.features.filter");

just before the filter_features_rebuild. This worked on the Panopoly/OpenAtrium install and no longer gives the error in the original post. I tried various combinations of features_include(TRUE) and clearing caches, but this direct include was the only method that really worked. Seems a bit kludgy, but since defaultconfig was already doing something special for filters I guess it's no worse than what it had before.

mpotter’s picture

Status: Active » Needs review
mpotter’s picture

StatusFileSize
new522 bytes

OK, drupal.org, why did that patch not attach? Let's try that again.

lslinnet’s picture

Issue summary: View changes
Status: Needs review » Fixed

Have reviewed, tested and commit this. Thanks for the work and thorough walkthrough of the issue.

Status: Fixed » Closed (fixed)

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

timaholt’s picture

Status: Closed (fixed) » Needs review
StatusFileSize
new1.64 KB

I was having this same issue with features with Taxonomy Vocab and permissions for that vocab in defaultconfig. I realized that Features has changed the original function that defaultconfig_component_rebuild_permissions was based on, so I'm including a new patch that updates this function. This patch fixed the issues I was having with defaultconfig and taxonomy permissions.

Anonymous’s picture

Applied the patch in #9, didn't test for what it was intended for but I received warnings on install.

Warning in features rebuild of adapt_core. No module defines permission "access contextual links". [warning]
Warning in features rebuild of adapt_core. No module defines permission "administer blocks". [warning]
Warning in features rebuild of adapt_core. No module defines permission "administer taxonomy".

The permissions are set correctly though.

timaholt’s picture

@samspinoy - those warnings are relevant, are you saying you see those but you also see those exact permissions set correctly in the database? In my testing when I see the errors I don't see the perms set correctly. But this is better than previously when I was getting a PDO exception.

Anonymous’s picture

are you saying you see those but you also see those exact permissions set correctly in the database

yes

saltednut’s picture

StatusFileSize
new1.77 KB
new632 bytes

This patch is working primarily except in the case of the drush command drush dra to rebuild everything. Just needs a minor addition to ensure the optional components are not empty when defaultconfig_rebuild_all(); is called.

mkhamash’s picture

heathdutton’s picture

Status: Needs review » Reviewed & tested by the community

Been using this in our builds for a long time. #14 works great.

joseph.olstad’s picture

Patch #14 works for us! Thanks.

lesleyfernandes’s picture

Status: Reviewed & tested by the community » Fixed

This issue was fixed on defaultconfig 7.x-1.0-alpha11:
https://www.drupal.org/project/defaultconfig/releases/7.x-1.0-alpha11

I am marking this issue as fixed.

lesleyfernandes’s picture

Status: Fixed » Closed (fixed)