Problem/Motivation
When installing drupal from an existing configuration that contains this module, installation fails with the following error:
Error: Call to a member function grantPermission() on null in google_analytics_install() (line 17 of /var/www/drupal/web/modules/contrib/google_analytics/google_analytics.install) #0 [internal function]: google_analytics_install()
#1 /var/www/drupal/web/core/lib/Drupal/Core/Extension/ModuleHandler.php(400): call_user_func_array()
#2 /var/www/drupal/web/core/lib/Drupal/Core/Extension/ModuleInstaller.php(357): Drupal\Core\Extension\ModuleHandler->invoke()
#3 /var/www/drupal/web/core/lib/Drupal/Core/ProxyClass/Extension/ModuleInstaller.php(83): Drupal\Core\Extension\ModuleInstaller->install()
#4 /var/www/drupal/web/core/lib/Drupal/Core/Config/ConfigImporter.php(872): Drupal\Core\ProxyClass\Extension\ModuleInstaller->install()
#5 /var/www/drupal/web/core/lib/Drupal/Core/Config/ConfigImporter.php(624): Drupal\Core\Config\ConfigImporter->processExtension()
#6 /var/www/drupal/web/core/lib/Drupal/Core/Config/ConfigImporter.php(561): Drupal\Core\Config\ConfigImporter->processExtensions()
#7 /var/www/drupal/web/core/lib/Drupal/Core/Config/Importer/ConfigImporterBatch.php(31): Drupal\Core\Config\ConfigImporter->doSyncStep()
#8 /var/www/drupal/web/core/includes/batch.inc(296): Drupal\Core\Config\Importer\ConfigImporterBatch::process()
#9 /var/www/drupal/web/core/includes/form.inc(955): _batch_process()
#10 /var/www/drupal/web/core/includes/install.core.inc(651): batch_process()
#11 /var/www/drupal/web/core/includes/install.core.inc(569): install_run_task()
#12 /var/www/drupal/web/core/includes/install.core.inc(119): install_run_tasks()
#13 /var/www/drupal/vendor/drush/drush/includes/drush.inc(69): install_drupal()
#14 /var/www/drupal/vendor/drush/drush/includes/drush.inc(53): drush_call_user_func_array()
#15 /var/www/drupal/vendor/drush/drush/src/Commands/core/SiteInstallCommands.php(169): drush_op()
#16 [internal function]: Drush\Commands\core\SiteInstallCommands->install()
#17 /var/www/drupal/vendor/consolidation/annotated-command/src/CommandProcessor.php(276): call_user_func_array()
#18 /var/www/drupal/vendor/consolidation/annotated-command/src/CommandProcessor.php(212): Consolidation\AnnotatedCommand\CommandProcessor->runCommandCallback()
#19 /var/www/drupal/vendor/consolidation/annotated-command/src/CommandProcessor.php(176): Consolidation\AnnotatedCommand\CommandProcessor->validateRunAndAlter()
#20 /var/www/drupal/vendor/consolidation/annotated-command/src/AnnotatedCommand.php(391): Consolidation\AnnotatedCommand\CommandProcessor->process()
#21 /var/www/drupal/vendor/symfony/console/Command/Command.php(326): Consolidation\AnnotatedCommand\AnnotatedCommand->execute()
#22 /var/www/drupal/vendor/symfony/console/Application.php(1081): Symfony\Component\Console\Command\Command->run()
#23 /var/www/drupal/vendor/symfony/console/Application.php(320): Symfony\Component\Console\Application->doRunCommand()
#24 /var/www/drupal/vendor/symfony/console/Application.php(174): Symfony\Component\Console\Application->doRun()
#25 /var/www/drupal/vendor/drush/drush/src/Runtime/Runtime.php(110): Symfony\Component\Console\Application->run()
#26 /var/www/drupal/vendor/drush/drush/src/Runtime/Runtime.php(40): Drush\Runtime\Runtime->doRun()
#27 /var/www/drupal/vendor/drush/drush/drush.php(139): Drush\Runtime\Runtime->run()
#28 /var/www/drupal/vendor/drush/drush/drush(4): require('...')
#29 /var/www/drupal/vendor/bin/drush(120): include('...')
#30 {main}.
Error: Call to a member function grantPermission() on null in /var/www/drupal/web/modules/contrib/google_analytics/google_analytics.install on line 17 #0 [internal function]: google_analytics_install()
Steps to reproduce
1. Install this module on a blank drupal (10.1.1) site.
2. Export config: drush cex -y
3. Reinstall drupal from the configuration: drush si -y --existing-config
4. You should see the above error.
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #16 | google_analytics-3373921-15.patch | 1.42 KB | bircher |
Issue fork google_analytics-3373921
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
bander2 commentedPossibly related to 3340020.
Comment #3
bander2 commentedI can confirm that this issue does not exist in Drupal 10.0.9. So, maybe this is due to a change in 10.1.
Comment #4
bander2 commentedComment #5
bander2 commentedComment #7
enrocean167 commentedWas running into this issue as well. MR looks good to me, thanks!
Comment #8
eiriksmHad a small suggestion in the MR. Otherwise, it works good and is simple enough :)
Comment #9
pookmish commentedI needed this with Drupal 10.1 as well. MR worked for me.
Comment #10
loopy1492 commentedThanks! Seems to be working for our site during pipelines ci run. I am adding a patch file from the MR diff for those who would rather use a flat patch file in composer.
Comment #11
seanbIn #3349663-7: Error: Call to a member function grantPermission() on null in userprotect_install() neclimdul found out what is happening. In short, this is caused by the change in #3112866: Remove special case of User module install. Modules are installed first and the default config for the modules is imported later. Since the authenticated user role is default config of the user module, the role doesn't exist yet in the install hook of other modules.
We can add the permissions using
user_role_grant_permissions()which is also used in core bymedia_install()andnode_install(). It basically uses the same checks as the patch, so we don't have to duplicate that code. We should probably also add a check for the user module existance (or add a dependency on the user module, but that seems a bit silly).Since this only seems to happen when installing sites from existing config, it shouldn't really matter that the module install hook can't add the permissions to the authenticated user role.
Comment #12
damienmckennaWhile we wait for core to fix the underlying problem there, I can also confirm that patch #10 resolves the immediate problem.
Comment #14
mxr576SAML have/had the same issue, IMO in this scenario we should just check if the config sync is running or not, in other words, whether the side is installed from config or not.
https://www.drupal.org/project/simplesamlphp_auth/issues/3392203
(Hiding patch to avoid confusion)
Comment #15
pacproduct commentedMR works great, thanks!
Comment #16
bircherI agree with #14 and disagree with #12, while in a deployment when this module is being added to a site, the subsequent config import will revert the change from the install hook, it is still not necessary and the latest patch is more correct and I wish more modules would do it that way.
RTBC +1 for the current code (attached patch for people with composer).
We use this in production and this patch allows us to install from config in our CI pipeline to run tests.
Comment #17
mxr576FTR, I confirmed that patch#15 reflects the latest state of MR#33
Comment #20
japerryLGTM -- Committed!