drush-ops / drush

Drush is a command-line shell and scripting interface for Drupal, a veritable Swiss Army knife designed to make life easier for those who spend their working hours hacking away at the command prompt.
https://www.drush.org
2.34k stars 1.08k forks source link

Some modules fail to install starting with 13.3.2 #6154

Closed totten closed 1 week ago

totten commented 2 weeks ago

Describe the bug

My project has some autobuild test/demo sites which include drush and https://www.drupal.org/project/userprotect.

Beginning with 13.3.2, drush en userprotect fails.

To Reproduce

  1. Create a site with this composer.json:
{
    "name": "drupal/recommended-project",
    "description": "Project template for Drupal projects with a relocated document root",
    "type": "project",
    "license": "GPL-2.0-or-later",
    "homepage": "https://www.drupal.org/project/drupal",
    "support": {
        "docs": "https://www.drupal.org/docs/user_guide/en/index.html",
        "chat": "https://www.drupal.org/node/314178"
    },
    "repositories": [
        {
            "type": "composer",
            "url": "https://packages.drupal.org/8"
        }
    ],
    "require": {
        "composer/installers": "^2.0",
        "drupal/core": "~10.3.0",
        "drupal/core-composer-scaffold": "~10.3.0",
        "drupal/core-project-message": "~10.3.0",
        "drupal/core-recommended": "~10.3.0",
        "drupal/userprotect": "~1.2.0",
        "drush/drush": "13.3.2"
    },
    "conflict": {
        "drupal/drupal": "*"
    },
    "minimum-stability": "dev",
    "prefer-stable": true,
    "config": {
        "allow-plugins": {
            "composer/installers": true,
            "drupal/core-composer-scaffold": true,
            "drupal/core-project-message": true,
            "phpstan/extension-installer": true,
            "dealerdirect/phpcodesniffer-composer-installer": true,
            "php-http/discovery": true,
            "cweagans/composer-patches": true,
            "civicrm/civicrm-asset-plugin": true,
            "civicrm/composer-downloads-plugin": true,
            "civicrm/composer-compile-plugin": true
        },
        "sort-packages": true
    },
    "extra": {
        "drupal-scaffold": {
            "locations": {
                "web-root": "web/"
            }
        },
        "installer-paths": {
            "web/core": [
                "type:drupal-core"
            ],
            "web/libraries/{$name}": [
                "type:drupal-library"
            ],
            "web/modules/contrib/{$name}": [
                "type:drupal-module"
            ],
            "web/profiles/contrib/{$name}": [
                "type:drupal-profile"
            ],
            "web/themes/contrib/{$name}": [
                "type:drupal-theme"
            ],
            "drush/Commands/contrib/{$name}": [
                "type:drupal-drush"
            ],
            "web/modules/custom/{$name}": [
                "type:drupal-custom-module"
            ],
            "web/profiles/custom/{$name}": [
                "type:drupal-custom-profile"
            ],
            "web/themes/custom/{$name}": [
                "type:drupal-custom-theme"
            ]
        },
        "drupal-core-project-message": {
            "include-keys": [
                "homepage",
                "support"
            ],
            "post-create-project-cmd-message": [
                "<bg=blue;fg=white>                                                         </>",
                "<bg=blue;fg=white>  Congratulations, you’ve installed the Drupal codebase  </>",
                "<bg=blue;fg=white>  from the drupal/recommended-project template!          </>",
                "<bg=blue;fg=white>                                                         </>",
                "",
                "<bg=yellow;fg=black>Next steps</>:",
                "  * Install the site: https://www.drupal.org/docs/installing-drupal",
                "  * Read the user guide: https://www.drupal.org/docs/user_guide/en/index.html",
                "  * Get support: https://www.drupal.org/support",
                "  * Get involved with the Drupal community:",
                "      https://www.drupal.org/getting-involved",
                "  * Remove the plugin that prints this message:",
                "      composer remove drupal/core-project-message"
            ]
        },
        "enable-patching": "true",
        "compile-mode": "all"
    }
}
  1. Install Drupal Core via CLI (drush site-install)

  2. Enable the module (drush en userprotect)

Expected behavior

Module installs without error.

Actual behavior

Installation fails:

drush en userprotect -v -v
 [info] Drush bootstrap phase: bootstrapDrupalRoot()
 [info] Change working directory to /home/me/bknix/build/tmpclean/web
 [info] Initialized Drupal 10.3.6 root directory at /home/me/bknix/build/tmpclean/web
 [info] Drush bootstrap phase: bootstrapDrupalSite()
 [info] Initialized Drupal site default at sites/default
 [info] Drush bootstrap phase: bootstrapDrupalConfiguration()
 [info] Drush bootstrap phase: bootstrapDrupalDatabase()
 [info] Successfully connected to the Drupal database.
 [info] Drush bootstrap phase: bootstrapDrupalFull()
 [info] Starting bootstrap to none
 [info] Drush bootstrap phase 0
 [info] Try to validate bootstrap phase 0
 [info] userprotect module installed.

In EntityTypeManager.php line 142:

  [Drupal\Component\Plugin\Exception\PluginNotFoundException]
  The "userprotect_rule" entity type does not exist.

Exception trace:
  at /home/me/bknix/build/tmpclean/web/core/lib/Drupal/Core/Entity/EntityTypeManager.php:142
 Drupal\Core\Entity\EntityTypeManager->getDefinition() at /home/me/bknix/build/tmpclean/web/core/lib/Drupal/Core/Entity/EntityTypeManager.php:260
 Drupal\Core\Entity\EntityTypeManager->getHandler() at /home/me/bknix/build/tmpclean/web/core/lib/Drupal/Core/Entity/EntityTypeManager.php:195
 Drupal\Core\Entity\EntityTypeManager->getStorage() at /home/me/bknix/build/tmpclean/web/modules/contrib/userprotect/src/UserProtectPermissions.php:51
 Drupal\userprotect\UserProtectPermissions->permissions() at n/a:n/a
 call_user_func() at /home/me/bknix/build/tmpclean/web/core/modules/user/src/PermissionHandler.php:166
 Drupal\user\PermissionHandler->buildPermissionsYaml() at /home/me/bknix/build/tmpclean/web/core/modules/user/src/PermissionHandler.php:125
 Drupal\user\PermissionHandler->getPermissions() at /home/me/bknix/build/tmpclean/web/core/modules/user/src/PermissionHandler.php:136
 Drupal\user\PermissionHandler->moduleProvidesPermissions() at /home/me/bknix/build/tmpclean/vendor/drush/drush/src/Commands/pm/PmCommands.php:410
 Drush\Commands\pm\PmCommands->getModuleLinks() at /home/me/bknix/build/tmpclean/vendor/drush/drush/src/Commands/pm/PmCommands.php:109
 Drush\Commands\pm\PmCommands->install() at n/a:n/a
 call_user_func_array() at /home/me/bknix/build/tmpclean/vendor/consolidation/annotated-command/src/CommandProcessor.php:276
 Consolidation\AnnotatedCommand\CommandProcessor->runCommandCallback() at /home/me/bknix/build/tmpclean/vendor/consolidation/annotated-command/src/CommandProcessor.php:212
 Consolidation\AnnotatedCommand\CommandProcessor->validateRunAndAlter() at /home/me/bknix/build/tmpclean/vendor/consolidation/annotated-command/src/CommandProcessor.php:175
 Consolidation\AnnotatedCommand\CommandProcessor->process() at /home/me/bknix/build/tmpclean/vendor/consolidation/annotated-command/src/AnnotatedCommand.php:387
 Consolidation\AnnotatedCommand\AnnotatedCommand->execute() at /home/me/bknix/build/tmpclean/vendor/symfony/console/Command/Command.php:326
 Symfony\Component\Console\Command\Command->run() at /home/me/bknix/build/tmpclean/vendor/symfony/console/Application.php:1096
 Symfony\Component\Console\Application->doRunCommand() at /home/me/bknix/build/tmpclean/vendor/symfony/console/Application.php:324
 Symfony\Component\Console\Application->doRun() at /home/me/bknix/build/tmpclean/vendor/symfony/console/Application.php:175
 Symfony\Component\Console\Application->run() at /home/me/bknix/build/tmpclean/vendor/drush/drush/src/Runtime/Runtime.php:110
 Drush\Runtime\Runtime->doRun() at /home/me/bknix/build/tmpclean/vendor/drush/drush/src/Runtime/Runtime.php:40
 Drush\Runtime\Runtime->run() at /home/me/bknix/build/tmpclean/vendor/drush/drush/drush.php:140
 include() at /home/me/bknix/build/tmpclean/vendor/bin/drush.php:119

Workaround

System Configuration

Q A
Drush version? 13.3.2
Drupal version? 10.3
PHP version 8.2
OS? Linux or Mac

Additional information

When I skimmed the changelog for 13.3.2, I didn't see any obvious reason for this to fail. But in my testing (autobuild sites on server; local site on Linux; local site on MacOS), the results have been consistent.

clayfreeman commented 2 weeks ago

I believe this is related to #6109. The check for whether or not to include a permissions link for a module will trigger dynamic permission generation for that module. The only problem is that the module may also provide dynamic permissions which rely on an entity type definition which is not yet available for use at the time the links are generated.

clayfreeman commented 2 weeks ago

I should add that you can replicate this with Drupal core's media module on a standard profile installation as well.

weitzman commented 2 weeks ago

I can reproduce this. A workaround PR is at https://github.com/drush-ops/drush/pull/6155.

My question is why is that entity type definition not available yet? The module has fully installed. When \Drupal\media\MediaPermissions::mediaTypePermissions runs, it has a stale entityTypeManager. I get that the container gets rebuilt after a module install but it would be nice if that didn't make stale the PermissionHandler's ETM.

bradjones1 commented 2 weeks ago

I ran into something similar when it came to field definitions going stale during a test on https://www.drupal.org/project/drupal/issues/2232427#comment-15837482 - an explicit cache-clear was required but honestly it feels like it shouldn't be necessary at all.

totten commented 6 days ago

Yay! Thanks @weitzman