Error on hook_install when invoked from drush site-install

Created on 30 May 2023, over 1 year ago

Problem/Motivation

There is a long standing issue (see here 🐛 hook_install() is invoked before the module's default config is installed during config import Needs work ) when accessing config from a hook_install().

In some scenarios (in my case, after upgrading to Drupal 10.1.x and running drush site-install --existing-config), the config is not ready when executing hook_install, so this will fail as the 'authenticated' role will return NULL:

  $role = Role::load('authenticated');

Steps to reproduce

Perform drush site-install --existing-config on an existing site that has GA module installed using Drupal 10.1.x.

Proposed resolution

Maybe the hook_install code should belong to a previous step (deploy hook? hook_post_config_import?) where we are sure that Drupal config is completely imported and present.

Remaining tasks

TBD

User interface changes

None

API changes

None

Data model changes

None

🐛 Bug report
Status

Needs work

Version

4.0

Component

Code

Created by

🇪🇸Spain idiaz.roncero Madrid

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @idiaz.roncero
  • @idiazroncero opened merge request.
  • Status changed to Needs work over 1 year ago
  • 🇪🇸Spain idiaz.roncero Madrid

    For those in need of a quick workaround, I've created a MR that simply bypasses the code when there is no Role loaded.

    This is clearly NOT the final solution, as it will result on divergent results (i.e: after a drush site-install --existing-config your permissions might be different as hook_install won't be executed!)

    This is just a workaround for those that need to have a temporary solution. I keep the issue as "Needs work"

Production build 0.71.5 2024