1. drush pm-uninstall google_analytics -y
  2. drush en google_analytics -y

[error] Error: Call to a member function grantPermission() on null in google_analytics_install() (line 17 of /var/www/html/web/modules/contrib/google_analytics/google_analytics.install) #0 [internal function]: google_analytics_install()
#1 /var/www/html/web/core/lib/Drupal/Core/Extension/ModuleHandler.php(417): call_user_func_array()
#2 /var/www/html/web/core/lib/Drupal/Core/Extension/ModuleInstaller.php(357): Drupal\Core\Extension\ModuleHandler->invoke()
#3 /var/www/html/web/core/lib/Drupal/Core/ProxyClass/Extension/ModuleInstaller.php(83): Drupal\Core\Extension\ModuleInstaller->install()
#4 /var/www/html/vendor/drush/drush/src/Drupal/Commands/pm/PmCommands.php(103): Drupal\Core\ProxyClass\Extension\ModuleInstaller->install()
#5 [internal function]: Drush\Drupal\Commands\pm\PmCommands->enable()
#6 /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(257): call_user_func_array()
#7 /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(212): Consolidation\AnnotatedCommand\CommandProcessor->runCommandCallback()
#8 /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(176): Consolidation\AnnotatedCommand\CommandProcessor->validateRunAndAlter()
#9 /var/www/html/vendor/consolidation/annotated-command/src/AnnotatedCommand.php(350): Consolidation\AnnotatedCommand\CommandProcessor->process()
#10 /var/www/html/vendor/symfony/console/Command/Command.php(255): Consolidation\AnnotatedCommand\AnnotatedCommand->execute()
#11 /var/www/html/vendor/symfony/console/Application.php(1039): Symfony\Component\Console\Command\Command->run()
#12 /var/www/html/vendor/symfony/console/Application.php(275): Symfony\Component\Console\Application->doRunCommand()
#13 /var/www/html/vendor/symfony/console/Application.php(149): Symfony\Component\Console\Application->doRun()
#14 /var/www/html/vendor/drush/drush/src/Runtime/Runtime.php(118): Symfony\Component\Console\Application->run()
#15 /var/www/html/vendor/drush/drush/src/Runtime/Runtime.php(48): Drush\Runtime\Runtime->doRun()
#16 /var/www/html/vendor/drush/drush/drush.php(72): Drush\Runtime\Runtime->run()
#17 /var/www/html/vendor/drush/drush/includes/preflight.inc(18): require('/var/www/html/v...')
#18 phar:///usr/local/bin/drush/bin/drush.php(143): drush_main()
#19 /usr/local/bin/drush(14): require('phar:///usr/loc...')
#20 {main}.
[07-Feb-2023 15:53:39 UTC] Error: Call to a member function grantPermission() on null in /var/www/html/web/modules/contrib/google_analytics/google_analytics.install on line 17 #0 [internal function]: google_analytics_install()
#1 /var/www/html/web/core/lib/Drupal/Core/Extension/ModuleHandler.php(417): call_user_func_array()
#2 /var/www/html/web/core/lib/Drupal/Core/Extension/ModuleInstaller.php(357): Drupal\Core\Extension\ModuleHandler->invoke()
#3 /var/www/html/web/core/lib/Drupal/Core/ProxyClass/Extension/ModuleInstaller.php(83): Drupal\Core\Extension\ModuleInstaller->install()
#4 /var/www/html/vendor/drush/drush/src/Drupal/Commands/pm/PmCommands.php(103): Drupal\Core\ProxyClass\Extension\ModuleInstaller->install()
#5 [internal function]: Drush\Drupal\Commands\pm\PmCommands->enable()
#6 /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(257): call_user_func_array()
#7 /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(212): Consolidation\AnnotatedCommand\CommandProcessor->runCommandCallback()
#8 /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(176): Consolidation\AnnotatedCommand\CommandProcessor->validateRunAndAlter()
#9 /var/www/html/vendor/consolidation/annotated-command/src/AnnotatedCommand.php(350): Consolidation\AnnotatedCommand\CommandProcessor->process()
#10 /var/www/html/vendor/symfony/console/Command/Command.php(255): Consolidation\AnnotatedCommand\AnnotatedCommand->execute()
#11 /var/www/html/vendor/symfony/console/Application.php(1039): Symfony\Component\Console\Command\Command->run()
#12 /var/www/html/vendor/symfony/console/Application.php(275): Symfony\Component\Console\Application->doRunCommand()
#13 /var/www/html/vendor/symfony/console/Application.php(149): Symfony\Component\Console\Application->doRun()
#14 /var/www/html/vendor/drush/drush/src/Runtime/Runtime.php(118): Symfony\Component\Console\Application->run()
#15 /var/www/html/vendor/drush/drush/src/Runtime/Runtime.php(48): Drush\Runtime\Runtime->doRun()
#16 /var/www/html/vendor/drush/drush/drush.php(72): Drush\Runtime\Runtime->run()
#17 /var/www/html/vendor/drush/drush/includes/preflight.inc(18): require('/var/www/html/v...')
#18 phar:///usr/local/bin/drush/bin/drush.php(143): drush_main()
#19 /usr/local/bin/drush(14): require('phar:///usr/loc...')
#20 {main}
Error: Call to a member function grantPermission() on null in google_analytics_install() (line 17 of /var/www/html/web/modules/contrib/google_analytics/google_analytics.install).
[warning] Drush command terminated abnormally.

Command icon 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

Vacilando created an issue. See original summary.

vacilando’s picture

Title: Error uninstalling Google Analytics module » Error enabling Google Analytics module after uninstall
Issue summary: View changes
vacilando’s picture

Issue summary: View changes
vacilando’s picture

Solved by deleting and adding role "authenticated". Not sure why it was needed.

In any case, I suggest making
$role = Role::load('authenticated'); (https://git.drupalcode.org/project/google_analytics/-/blob/4.x/google_an...)
conditional, as it's not guaranteed that every system will have a role with that name.

vacilando’s picture

Priority: Major » Normal
arunkumark’s picture

Status: Active » Closed (cannot reproduce)
Issue tags: +Needs steps to reproduce
StatusFileSize
new67.71 KB

Verified the issue with the latest version of Drupal. Unable to replicate the issue. Attached screenshot of the successful installation and uninstall of the module.

Drupal core: 10.0.3
Google Analytics: 4.0.2

Install & uninstall

Feel free to reopen the issue, if able to reproduce it.

chriseikelboom’s picture

I had a similar situation where the module was enabled on a different develop environment (most likely with authenticated role present in the database).

Than when I was setting up a new develop environment (with recent database from production without authenticated role), It caused an error on the drush deploy.

Error: Call to a member function grantPermission() on null in /var/www/html/htdocs/modules/contrib/google_analytics/google_analytics.install on line 17 #0 [internal function]: google_
  analytics_install(true)

I think you can replicate the situation by first removing the authenticated role and than installing the module.

vinlaurens’s picture

Status: Closed (cannot reproduce) » Active
StatusFileSize
new159.27 KB

Unfortunately, I was able to reproduce this using a pipeline in Gitlab which does a fresh site install with drush.

Drupal version: 10.1.2
Google Analytics: 4.0.2
PHP: 8.1

stefan lehmann’s picture

We have the same issue as vinlaurens with the same Stack. This error comes up as part of the Gitlab CI pipeline test process. A clean install of Drupal but with an existing configuration of modules which have to be installed etc.

Here the last command that leads to this error. I assume the user role just doesn't exist yet at the point when this module is installed.

$ docker-compose exec -T --user www-data php /bin/sh -c "cd /var/www/html/drupal/ && composer build"
> drush site:install minimal --existing-config --db-url=mysql://user:password@mariadb:port/drupal -y
 You are about to:
 * DROP all tables in your 'drupal' database.
 // Do you want to continue?: yes.                                              
 [notice] Starting Drupal installation. This takes a while.
 [notice] Performed install task: install_select_language
 [notice] Performed install task: install_select_profile
 [notice] Performed install task: install_load_profile
 [notice] Performed install task: install_verify_requirements
 [notice] Performed install task: install_verify_database_ready
 [notice] Performed install task: install_base_system
 [notice] Performed install task: install_bootstrap_full
 [error]  Error: Call to a member function grantPermission() on null in google_analytics_install() (line 17 of /var/www/html/drupal/web/modules/contrib/google_analytics/google_analytics.install) #0 [internal function]: google_analytics_install()

I just wrote a little check if that user role was successfully loaded.

stefan lehmann’s picture

Status: Active » Needs review
stefan lehmann’s picture

Funny I just realised after doing it last weekend that this is just a duplicate of https://www.drupal.org/project/google_analytics/issues/3373921

I basically created exactly the same patch as the guy in that ticket. :-)

stefan lehmann’s picture

Status: Needs review » Closed (duplicate)