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

Database update step for drush deploy behaves differently than drush updb --no-cache-clear #5952

Closed
elaman opened this issue Apr 8, 2024 · 2 comments

Comments

@elaman
Copy link
Contributor

elaman commented Apr 8, 2024

Describe the bug
We use drush deploy in our CI, however recently we had two deploy failures. The most recent one being simple_sitemap module changing its services definition. In both cases database update step in drush deploy executed in a different way than drush updb --no-cache-clear it is trying to create a shortcut for.

To Reproduce

  • Install vanilla Drupal 10. Use drush si to install it.
  • Install old version of simple_sitemap composer require drupal/simple_sitemap:4.1.8 and enable it using drush en simple_sitemap.
  • Update simple_sitemap to the latest version composer require drupal/simple_sitemap:4.1.9.
  • Execute drush deploy.

Expected behavior
The command should've updated the database and imported the configs successfully.

Actual behavior
Immediately received an error:

TypeError: Drupal\simple_sitemap\Queue\QueueWorker::__construct(): Argument #2 ($key_value) must be of type Drupal\Core\KeyValueStore\KeyValueFactoryInterface, Drupal\Core\State\State given, called in /var/www/html/web/core/lib/Drupal/Component/DependencyInjection/Container.php on line 259 in /var/www/html/web/modules/contrib/simple_sitemap/src/Queue/QueueWorker.php on line 153 #0 /var/www/html/web/core/lib/Drupal/Component/DependencyInjection/Container.php(259): Drupal\simple_sitemap\Queue\QueueWorker->__construct(Object(Drupal\simple_sitemap\Settings), Object(Drupal\Core\State\State), Object(Drupal\simple_sitemap\Queue\SimpleSitemapQueue), Object(Drupal\simple_sitemap\Logger), Object(Drupal\Core\Extension\ModuleHandler), Object(Drupal\Core\Entity\EntityTypeManager), Object(Drupal\Core\ProxyClass\Lock\DatabaseLockBackend))
#1 /var/www/html/web/core/lib/Drupal/Component/DependencyInjection/Container.php(177): Drupal\Component\DependencyInjection\Container->createService(Array, 'simple_sitemap....')
#2 /var/www/html/web/core/lib/Drupal/Component/DependencyInjection/Container.php(440): Drupal\Component\DependencyInjection\Container->get('simple_sitemap....', 1)
#3 /var/www/html/web/core/lib/Drupal/Component/DependencyInjection/Container.php(237): Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters(Array)
#4 /var/www/html/web/core/lib/Drupal/Component/DependencyInjection/Container.php(177): Drupal\Component\DependencyInjection\Container->createService(Array, 'simple_sitemap....')
#5 /var/www/html/vendor/drush/drush/src/Runtime/LegacyServiceInstantiator.php(288): Drupal\Component\DependencyInjection\Container->get('simple_sitemap....')
#6 /var/www/html/vendor/drush/drush/src/Runtime/LegacyServiceInstantiator.php(253): Drush\Runtime\LegacyServiceInstantiator->resolveFromContainer(Object(Drupal\Core\DependencyInjection\Container), 'simple_sitemap....')
#7 [internal function]: Drush\Runtime\LegacyServiceInstantiator->resolveArgument('@simple_sitemap...')
#8 /var/www/html/vendor/drush/drush/src/Runtime/LegacyServiceInstantiator.php(223): array_map(Array, Array)
#9 /var/www/html/vendor/drush/drush/src/Runtime/LegacyServiceInstantiator.php(193): Drush\Runtime\LegacyServiceInstantiator->resolveArguments(Array)
#10 /var/www/html/vendor/drush/drush/src/Runtime/LegacyServiceInstantiator.php(174): Drush\Runtime\LegacyServiceInstantiator->instantiateObject('Drupal\simple_s...', Array)
#11 /var/www/html/vendor/drush/drush/src/Runtime/LegacyServiceInstantiator.php(131): Drush\Runtime\LegacyServiceInstantiator->create('Drupal\simple_s...', Array, Array)
#12 /var/www/html/vendor/drush/drush/src/Runtime/LegacyServiceInstantiator.php(60): Drush\Runtime\LegacyServiceInstantiator->instantiateServices(Array)
#13 /var/www/html/vendor/drush/drush/src/Boot/DrupalBoot8.php(257): Drush\Runtime\LegacyServiceInstantiator->loadServiceFiles(Array)
#14 /var/www/html/vendor/drush/drush/src/Boot/DrupalBoot8.php(233): Drush\Boot\DrupalBoot8->addDrupalModuleDrushCommands(Object(Drush\Boot\BootstrapManager))
#15 /var/www/html/vendor/drush/drush/src/Boot/BootstrapManager.php(236): Drush\Boot\DrupalBoot8->bootstrapDrupalFull(Object(Drush\Boot\BootstrapManager), Object(Consolidation\AnnotatedCommand\AnnotationData))
#16 /var/www/html/vendor/drush/drush/src/Boot/BootstrapManager.php(377): Drush\Boot\BootstrapManager->doBootstrap(5, 5, Object(Consolidation\AnnotatedCommand\AnnotationData))
#17 /var/www/html/vendor/drush/drush/src/Boot/BootstrapManager.php(329): Drush\Boot\BootstrapManager->bootstrapToPhaseIndex(5, Object(Consolidation\AnnotatedCommand\AnnotationData))
#18 /var/www/html/vendor/drush/drush/src/Boot/BootstrapHook.php(36): Drush\Boot\BootstrapManager->bootstrapToPhase('full', Object(Consolidation\AnnotatedCommand\AnnotationData))
#19 /var/www/html/vendor/consolidation/annotated-command/src/Hooks/Dispatchers/InitializeHookDispatcher.php(44): Drush\Boot\BootstrapHook->initialize(Object(Symfony\Component\Console\Input\ArgvInput), Object(Consolidation\AnnotatedCommand\AnnotationData))
#20 /var/www/html/vendor/consolidation/annotated-command/src/Hooks/Dispatchers/InitializeHookDispatcher.php(36): Consolidation\AnnotatedCommand\Hooks\Dispatchers\InitializeHookDispatcher->doInitializeHook(Object(Drush\Boot\BootstrapHook), Object(Symfony\Component\Console\Input\ArgvInput), Object(Consolidation\AnnotatedCommand\AnnotationData))
#21 /var/www/html/vendor/consolidation/annotated-command/src/Hooks/Dispatchers/InitializeHookDispatcher.php(29): Consolidation\AnnotatedCommand\Hooks\Dispatchers\InitializeHookDispatcher->callInitializeHook(Object(Drush\Boot\BootstrapHook), Object(Symfony\Component\Console\Input\ArgvInput), Object(Consolidation\AnnotatedCommand\AnnotationData))
#22 /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(145): Consolidation\AnnotatedCommand\Hooks\Dispatchers\InitializeHookDispatcher->initialize(Object(Symfony\Component\Console\Input\ArgvInput), Object(Consolidation\AnnotatedCommand\AnnotationData))
#23 /var/www/html/vendor/consolidation/annotated-command/src/AnnotatedCommand.php(376): Consolidation\AnnotatedCommand\CommandProcessor->initializeHook(Object(Symfony\Component\Console\Input\ArgvInput), Array, Object(Consolidation\AnnotatedCommand\AnnotationData))
#24 /var/www/html/vendor/symfony/console/Command/Command.php(292): Consolidation\AnnotatedCommand\AnnotatedCommand->initialize(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#25 /var/www/html/vendor/symfony/console/Application.php(1096): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#26 /var/www/html/vendor/symfony/console/Application.php(324): Symfony\Component\Console\Application->doRunCommand(Object(Consolidation\AnnotatedCommand\AnnotatedCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#27 /var/www/html/vendor/symfony/console/Application.php(175): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#28 /var/www/html/vendor/drush/drush/src/Runtime/Runtime.php(110): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#29 /var/www/html/vendor/drush/drush/src/Runtime/Runtime.php(40): Drush\Runtime\Runtime->doRun(Array, Object(Symfony\Component\Console\Output\ConsoleOutput))
#30 /var/www/html/vendor/drush/drush/drush.php(139): Drush\Runtime\Runtime->run(Array)
#31 /var/www/html/vendor/drush/drush/drush(4): require('/var/www/html/v...')
#32 /var/www/html/vendor/bin/drush(119): include('/var/www/html/v...')
#33 {main}
TypeError: Drupal\simple_sitemap\Queue\QueueWorker::__construct(): Argument #2 ($key_value) must be of type Drupal\Core\KeyValueStore\KeyValueFactoryInterface, Drupal\Core\State\State given, called in /var/www/html/web/core/lib/Drupal/Component/DependencyInjection/Container.php on line 259 in Drupal\simple_sitemap\Queue\QueueWorker->__construct() (line 153 of /var/www/html/web/modules/contrib/simple_sitemap/src/Queue/QueueWorker.php).
[warning] Drush command terminated abnormally.

Workaround
If you run drush updb --no-cache-clear instead, it will complete database updates successfully. Then you can run other commands in order with no issues.

System Configuration

Q A
Drush version? 12.5.1.0
Drupal version? 10.x
PHP version 8.x
OS? Linux

Additional information
Adding #[CLI\Kernel(name: 'update')] annotation from drush updb to drush deploy command solves the issue.

elaman added a commit to elaman/drush that referenced this issue Apr 8, 2024
@elaman elaman changed the title drush deploy behaves differently than commands it is replacing Database update step for drush deploy behaves differently than drush updb --no-cache-clear Apr 8, 2024
@spleshka
Copy link

spleshka commented Apr 8, 2024

This may be the reason why some devs recommend running drush cr before drush deploy to make sure that cache of services definitions is flushed before running database updates (which would fail otherwise for cases like the one described above). The fix provided in the PR hopefully removes the need of cache rebuild before the deploy command, but we were not entirely sure about potential side effects of adding #[CLI\Kernel(name: 'update')] to the deploy command, especially in the environments where cache is moved to the memory storages.

During testing of the change we've spotted that drush updb --no-cache-clear command flushes cache bins anyway, so presumably it's safe to keep #[CLI\Kernel(name: 'update')] for all use cases, but an additional confirmation would be greatly appreciated.

weitzman added a commit that referenced this issue Apr 10, 2024
…an `drush updb --no-cache-clear` (#5953)

* Update DeployCommands.php

Fixes the issue #5952

* Dont bootstrap with deploy command

---------

Co-authored-by: Moshe Weitzman <weitzman@tejasa.com>
@weitzman
Copy link
Member

#5953 fixed this

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

No branches or pull requests

3 participants