modules_install hook causes constraint violation: 1048 Column 'module' cannot be null: INSERT INTO {role_permission} (rid, permission, module) I am trying to set several permissions when a feature is being enabled (a new content type). 
By default this content type is disabled, and an admin can go to structure/features and enable it

under docroot/profile/my_profile/features/foo I created the following foo.install file

function foo_modules_installed($modules) {
 if (in_array('foo', $modules)) {
  $perms = array(
    'create foo content',
    'edit own foo content',
    ); 
      user_role_grant_permissions(user_role_load_by_name('publisher')-&gt;rid, $perms);
      user_role_grant_permissions(user_role_load_by_name('administrator')-&gt;rid, $perms);
}
}


but when I go to structure/features and enable it, I get the following error 

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'module' cannot be null: INSERT INTO {role_permission} (rid, permission, module


I tried different hooks, like enabled and so forth and all have the same issue.

How can I have a feature disabled by default, but still grant permissions to some users? What am I doing wrong
Seems like a hook_install() in the .install file for the feature will work if called with 

drupal_flush_all_caches();


I am not sure if this is the best solution, but it seems to work for me