Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent drush from crushing, when module's command extends non-existent class #5860

Open
ilyano opened this issue Feb 8, 2024 · 4 comments · May be fixed by #5861
Open

Prevent drush from crushing, when module's command extends non-existent class #5860

ilyano opened this issue Feb 8, 2024 · 4 comments · May be fixed by #5861

Comments

@ilyano
Copy link

ilyano commented Feb 8, 2024

Describe the bug
I'm trying to update from D9 to D10 and to Drush 12.4.3. Along with core update I have to update path_redirect_import module from 1 to 2 version. Version 1 of this module has following dependencies and version 2 has couple of new ones. But the problem is that old version has drush command, extending DrushCommands class and new version's command extends MigrateToolsCommand. On D9 version of the site, which I'm trying to update, migrate_tools module is not enabled and thus system is not aware of its drush command representing class.

To Reproduce
Install site on D9 and Drush 10. Install path_redirect_import module 1st version. Update code to D10, Drush 12 and path_redirect_import to 2. Try to execute any drush command.

Expected behavior
Drush skips such cases without crushing.

Actual behavior
Drush fails with following error:

Error: Class "Drupal\migrate_tools\Drush\Commands\MigrateToolsCommands" not found in /var/www/html/web/modules/contrib/path_redirect_import/src/Drush/Commands/PathRedirectImportCommands.php on line 30 #0 /var/www/html/vendor/composer/ClassLoader.php(576): include()
#1 /var/www/html/vendor/composer/ClassLoader.php(427): Composer\Autoload\{closure}()
#2 [internal function]: Composer\Autoload\ClassLoader->loadClass()
#3 /var/www/html/vendor/drush/drush/src/Runtime/LegacyServiceInstantiator.php(199): ReflectionClass->__construct()
#4 /var/www/html/vendor/drush/drush/src/Runtime/LegacyServiceInstantiator.php(177): Drush\Runtime\LegacyServiceInstantiator->instantiateObject()
#5 /var/www/html/vendor/drush/drush/src/Runtime/LegacyServiceInstantiator.php(128): Drush\Runtime\LegacyServiceInstantiator->create()
#6 /var/www/html/vendor/drush/drush/src/Runtime/LegacyServiceInstantiator.php(60): Drush\Runtime\LegacyServiceInstantiator->instantiateServices()
#7 /var/www/html/vendor/drush/drush/src/Boot/DrupalBoot8.php(257): Drush\Runtime\LegacyServiceInstantiator->loadServiceFiles()
#8 /var/www/html/vendor/drush/drush/src/Boot/DrupalBoot8.php(233): Drush\Boot\DrupalBoot8->addDrupalModuleDrushCommands()
#9 /var/www/html/vendor/drush/drush/src/Boot/BootstrapManager.php(236): Drush\Boot\DrupalBoot8->bootstrapDrupalFull()
#10 /var/www/html/vendor/drush/drush/src/Boot/BootstrapManager.php(422): Drush\Boot\BootstrapManager->doBootstrap()
#11 /var/www/html/vendor/drush/drush/src/Boot/BootstrapManager.php(357): Drush\Boot\BootstrapManager->bootstrapMax()
#12 /var/www/html/vendor/drush/drush/src/Boot/BootstrapManager.php(329): Drush\Boot\BootstrapManager->bootstrapToPhaseIndex()
#13 /var/www/html/vendor/drush/drush/src/Boot/BootstrapHook.php(36): Drush\Boot\BootstrapManager->bootstrapToPhase()
#14 /var/www/html/vendor/consolidation/annotated-command/src/Hooks/Dispatchers/InitializeHookDispatcher.php(44): Drush\Boot\BootstrapHook->initialize()
#15 /var/www/html/vendor/consolidation/annotated-command/src/Hooks/Dispatchers/InitializeHookDispatcher.php(36): Consolidation\AnnotatedCommand\Hooks\Dispatchers\InitializeHookDispatcher->doInitializeHook()
#16 /var/www/html/vendor/consolidation/annotated-command/src/Hooks/Dispatchers/InitializeHookDispatcher.php(29): Consolidation\AnnotatedCommand\Hooks\Dispatchers\InitializeHookDispatcher->callInitializeHook()
#17 /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(145): Consolidation\AnnotatedCommand\Hooks\Dispatchers\InitializeHookDispatcher->initialize()
#18 /var/www/html/vendor/consolidation/annotated-command/src/AnnotatedCommand.php(376): Consolidation\AnnotatedCommand\CommandProcessor->initializeHook()
#19 /var/www/html/vendor/symfony/console/Command/Command.php(292): Consolidation\AnnotatedCommand\AnnotatedCommand->initialize()
#20 /var/www/html/vendor/symfony/console/Application.php(1096): Symfony\Component\Console\Command\Command->run()
#21 /var/www/html/vendor/symfony/console/Application.php(324): Symfony\Component\Console\Application->doRunCommand()
#22 /var/www/html/vendor/symfony/console/Application.php(175): Symfony\Component\Console\Application->doRun()
#23 /var/www/html/vendor/drush/drush/src/Runtime/Runtime.php(110): Symfony\Component\Console\Application->run()
#24 /var/www/html/vendor/drush/drush/src/Runtime/Runtime.php(40): Drush\Runtime\Runtime->doRun()
#25 /var/www/html/vendor/drush/drush/drush.php(139): Drush\Runtime\Runtime->run()
#26 /var/www/html/vendor/drush/drush/drush(4): require('...')
#27 /var/www/html/vendor/bin/drush(119): include('...')
#28 {main}

Workaround
Of course, we can enable needed modules before deployment, but I think, it is helpful for automated deployment to have Drush expecting such cases.

System Configuration

Q A
Drush version? 12.4.3
Drupal version? 10.2.2
PHP version 8.3
OS? Linux

Additional information
Found this PR, which adds try/catch, but in my case this check needs to be added in other places, where new \ReflectionClass($class) is used

@andypost
Copy link
Contributor

andypost commented Feb 8, 2024

I think you need to file issue to the module's queue as well to provide some compatibility with migrate commands

@andypost
Copy link
Contributor

andypost commented Feb 8, 2024

@ilyano
Copy link
Author

ilyano commented Mar 13, 2024

Thanks for information! Yes, I saw this issue, but I'm not sure, that my problem can be fixed from the module's side, because usually we enable modules via hook_update function, but this function is executed using drush mostly.

So, we can enable necessary modules prior to deploy or try to run update.php instead of running drush command for hook_update function. But having this error fixed in drush is also a good way, I think, as long as we already fixed similar issue before.

@weitzman
Copy link
Member

weitzman commented May 4, 2024

Two workarounds:

  1. It is not supported to extend a commandfile's class. Drush core commandfiles are now all final to communicate that.
  2. Also, stop using drush.services.yml files and use the create() method instead. That avoids this issue as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants