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

TypErrors in LegacySevericeInstantiator.php with 12.0.0-RC1 and above #5625

Closed
rpkoller opened this issue Jun 6, 2023 · 7 comments
Closed

Comments

@rpkoller
Copy link

rpkoller commented Jun 6, 2023

Describe the bug
I've upgraded to Drush 12.0.0 yesterday on a Drupal 10.1.0-beta1 site running on DDEV latest HEAD (with PHP 8.2) on MacOS 12.6.1. using Mutagen. i had drush cr and drush updatedb -y as post-install-cmd and post-update-cmd in the composer.json's scripts section. Drush is installed as require-dev. i immediately ran into the following warnings and type errors: https://gist.github.com/rpkoller/de810e220ea020aad94ac9d987813f40 . i've downgraded to 11.5.1 and removed the scripts section to rule out a potential race condition during the install that drush cr is ran too close after the update. i've upgraded to 12.0.0 again. right after the update i did at first a ddev restart and then went into the sites admin interface and cleared the caches there. after that i've retried to run ddev drush cr and ddev drush updatedb. the same errors happened again. i've then changed the project to PHP 8.1 and did a ddev restart, the error persisted.
I've then downgraded to Drush 12.0.0-beta1 and the error was gone. i then went one version up to 12.0.0-RC1 and the error was back (as seen in the gist). the only difference between 12.0.0-RC1 and 12.0.0 is the line the errors happens.
I've searched the issue queue but was unable to find an issue in relation to LegacySevericeInstantiator.php. I tried to narrow down the problem as close as possible but am out of ideas if it is necessary to narrow things down further (am not a developer). if you need more information or if i should try to debug more let me know please.

To Reproduce

  • ddev composer require "drush/drush:12.0.0" -W with
    "scripts": {
        "post-install-cmd": [
            "drush cr",
            "drush updatedb -y"
        ],
        "post-update-cmd": [
            "drush cr",
            "drush updatedb -y"
        ]
    }

in the scripts section of the composer.json file

Expected behavior
no errors and all the commands running through as usual

Actual behavior
as mentioned before. that kind of errors get returned no matter what command is run
https://gist.github.com/rpkoller/de810e220ea020aad94ac9d987813f40 (happens even for ddev drush status)

Workaround
Go back to Drush 12.0.0-beta1 or 11.5.1

System Configuration

Q A
Drush version? 12.0.0
Drupal version? 10.1-beta1
PHP version 8.2
OS? Mac 12.6.1 using the latest version of DDEV HEAD

Additional information
Add any other context about the problem here.

@greg-1-anderson
Copy link
Member

the only difference between 12.0.0-RC1 and 12.0.0 is the line the errors happens.

It appears to me that the line where the error happens was introduced with the first version of the LegacyServiceInstantiator. Seems that there is some object that is optional in the drush.services.yml implementation that is now required by the LegacyServiceInstantiator. The trigger is probably some contrib module with a Drush extension, but I suppose it could be a Drush core command. The fix is to make the LegacyServiceInstantiator work more like the Symfony DI container implementation.

@rpkoller
Copy link
Author

rpkoller commented Jun 6, 2023

Your suspicion in regards of the contrib module drush extension might be correct. i've tried a few things:

  • I've tried to uninstall the contrib modules step by step and run composer removeafter the uninstall to see if i am able to fix things. on the site in question the contrib modules with drush extensions were automatic_updates, project_browser and devel. but unfortunately with the back and forth between drush versions, the errors something went wrong along the way and i ran into another and somehow bricked the testintall. uncertain if i am able to revive it.
  • i've spun up a new site in ddev (drupal 10.1.x-dev, php 8.2, drush 12.0.0). the install went through flawlessly and i am able to run all the commands without any errors.
  • i've spun up another site in ddev (drupal 10.0.9, php 8.2 , drush 12.0.0). the install went through flawlessly and i am able to run all the commands without any errors. after that i've set the the minimum stability to alpha in den composer.json and the ran ddev composer require "drupal/automatic_updates:3.0.x-dev@dev". i then went into the admin interface and installed automatic_updates and package manager. after that i tried to run ddev drush status and i got:
[warning] Undefined array key "class" LegacyServiceInstantiator.php:82
TypeError: ReflectionClass::__construct(): Argument #1 ($objectOrClass) must be of type object|string, null given in /var/www/html/vendor/drush/drush/src/Runtime/LegacyServiceInstantiator.php on line 145 #0 /var/www/html/vendor/drush/drush/src/Runtime/LegacyServiceInstantiator.php(145): ReflectionClass->__construct(NULL)
#1 /var/www/html/vendor/drush/drush/src/Runtime/LegacyServiceInstantiator.php(127): Drush\Runtime\LegacyServiceInstantiator->instantiateObject(NULL, Array)
#2 /var/www/html/vendor/drush/drush/src/Runtime/LegacyServiceInstantiator.php(81): Drush\Runtime\LegacyServiceInstantiator->create(NULL, Array, Array)
#3 /var/www/html/vendor/drush/drush/src/Runtime/LegacyServiceInstantiator.php(59): Drush\Runtime\LegacyServiceInstantiator->instantiateServices(Array)
#4 /var/www/html/vendor/drush/drush/src/Boot/DrupalBoot8.php(261): Drush\Runtime\LegacyServiceInstantiator->loadServiceFiles(Array)
#5 /var/www/html/vendor/drush/drush/src/Boot/DrupalBoot8.php(237): Drush\Boot\DrupalBoot8->addDrupalModuleDrushCommands(Object(Drush\Boot\BootstrapManager))
#6 /var/www/html/vendor/drush/drush/src/Boot/BootstrapManager.php(236): Drush\Boot\DrupalBoot8->bootstrapDrupalFull(Object(Drush\Boot\BootstrapManager), NULL)
#7 /var/www/html/vendor/drush/drush/src/Boot/BootstrapManager.php(422): Drush\Boot\BootstrapManager->doBootstrap(5, 6, NULL)
#8 /var/www/html/vendor/drush/drush/src/Boot/BootstrapManager.php(357): Drush\Boot\BootstrapManager->bootstrapMax(6)
#9 /var/www/html/vendor/drush/drush/src/Boot/BootstrapManager.php(329): Drush\Boot\BootstrapManager->bootstrapToPhaseIndex(-2, Object(Consolidation\AnnotatedCommand\AnnotationData))
#10 /var/www/html/vendor/drush/drush/src/Boot/BootstrapHook.php(36): Drush\Boot\BootstrapManager->bootstrapToPhase('max', Object(Consolidation\AnnotatedCommand\AnnotationData))
#11 /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))
#12 /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))
#13 /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))
#14 /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))
#15 /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))
#16 /var/www/html/vendor/symfony/console/Command/Command.php(278): Consolidation\AnnotatedCommand\AnnotatedCommand->initialize(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#17 /var/www/html/vendor/symfony/console/Application.php(1040): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#18 /var/www/html/vendor/symfony/console/Application.php(314): Symfony\Component\Console\Application->doRunCommand(Object(Consolidation\AnnotatedCommand\AnnotatedCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#19 /var/www/html/vendor/symfony/console/Application.php(168): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#20 /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))
#21 /var/www/html/vendor/drush/drush/src/Runtime/Runtime.php(40): Drush\Runtime\Runtime->doRun(Array, Object(Symfony\Component\Console\Output\ConsoleOutput))
#22 /var/www/html/vendor/drush/drush/drush.php(139): Drush\Runtime\Runtime->run(Array)
#23 /var/www/html/vendor/drush/drush/drush(4): require('/var/www/html/v...')
#24 /var/www/html/vendor/bin/drush(120): include('/var/www/html/v...')
#25 {main}
TypeError: ReflectionClass::__construct(): Argument #1 ($objectOrClass) must be of type object|string, null given in ReflectionClass->__construct() (line 145 of /var/www/html/vendor/drush/drush/src/Runtime/LegacyServiceInstantiator.php).
 [warning] Drush command terminated abnormally.
Failed to run drush status: exit status 1

so it looks like the issue is caused by contrib modules?

Update: tried to install project_browser and webprofiler with it's dependency devel and the error doesn't show up there (uninstalled and removed automatic_updates before). so it looks like automatic_updates was the only contrib module that was causing the issue

@greg-1-anderson
Copy link
Member

[warning] Undefined array key "class" LegacyServiceInstantiator.php:82

This is a completely different error than the one you first reported; this one looks like it should be pretty easy to fix. The original report is a head-scratcher, though; if you find a way to reproduce from a fresh install of Drupal (plus contrib install and enable), it would be very helpful.

somehow bricked the testintall. uncertain if i am able to revive it.

If you mess up your composer file when testing alternatives, you can often fix everything and go back to the way things were before by restoring composer.json and composer.lock and then running composer install

@greg-1-anderson
Copy link
Member

OK, we have done some investigation and have discovered that some folks use features of the Symfony DI container that we don't / can't support. So, we're going to pre-validate the drush.services.yml file, and if we see anything we don't understand, we'll just skip the whole file and emit a warning message. So, this means you won't be able to use the Drush commands from incompatible modules when you upgrade to Drush 12, but at least your site won't catch fire, and the module maintainer should, in theory, eventually notice and fix the problem.

@rpkoller
Copy link
Author

rpkoller commented Jun 6, 2023

i havent looked close enough at the output i've pasted in the followup comment. on the first look it seemed similar but you are right in detail the pasted snippet and the output from the gist differs signicantly.

unfortunately i already removed the project from ddev and i've omitted a snapshot on deletion. therefore i had no db backup available anymore :( but i went ahead and reinstalled the site with the still available codebase and tested around a bit. as I already noted the module that caused the error was potentially automatic updates and with just automatic updates and package manager installed and upgrading to drush 12 i am able to reproduce the error (at least the snippet still looks like on closer look). with package_manager alone there is also no error.:

$> ddev drush cr
 [warning] Undefined array key "class" LegacyServiceInstantiator.php:82
TypeError: ReflectionClass::__construct(): Argument #1 ($objectOrClass) must be of type object|string, null given in /var/www/html/vendor/drush/drush/src/Runtime/LegacyServiceInstantiator.php on line 145 #0 /var/www/html/vendor/drush/drush/src/Runtime/LegacyServiceInstantiator.php(145): ReflectionClass->__construct(NULL)
#1 /var/www/html/vendor/drush/drush/src/Runtime/LegacyServiceInstantiator.php(127): Drush\Runtime\LegacyServiceInstantiator->instantiateObject(NULL, Array)
#2 /var/www/html/vendor/drush/drush/src/Runtime/LegacyServiceInstantiator.php(81): Drush\Runtime\LegacyServiceInstantiator->create(NULL, Array, Array)
#3 /var/www/html/vendor/drush/drush/src/Runtime/LegacyServiceInstantiator.php(59): Drush\Runtime\LegacyServiceInstantiator->instantiateServices(Array)
#4 /var/www/html/vendor/drush/drush/src/Boot/DrupalBoot8.php(261): Drush\Runtime\LegacyServiceInstantiator->loadServiceFiles(Array)
#5 /var/www/html/vendor/drush/drush/src/Boot/DrupalBoot8.php(237): Drush\Boot\DrupalBoot8->addDrupalModuleDrushCommands(Object(Drush\Boot\BootstrapManager))
#6 /var/www/html/vendor/drush/drush/src/Boot/BootstrapManager.php(236): Drush\Boot\DrupalBoot8->bootstrapDrupalFull(Object(Drush\Boot\BootstrapManager), NULL)
#7 /var/www/html/vendor/drush/drush/src/Boot/BootstrapManager.php(422): Drush\Boot\BootstrapManager->doBootstrap(5, 6, NULL)
#8 /var/www/html/vendor/drush/drush/src/Application.php(228): Drush\Boot\BootstrapManager->bootstrapMax()
#9 /var/www/html/vendor/drush/drush/src/Application.php(194): Drush\Application->bootstrapAndFind('cr')
#10 /var/www/html/vendor/symfony/console/Application.php(262): Drush\Application->find('cr')
#11 /var/www/html/vendor/symfony/console/Application.php(174): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#12 /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))
#13 /var/www/html/vendor/drush/drush/src/Runtime/Runtime.php(40): Drush\Runtime\Runtime->doRun(Array, Object(Symfony\Component\Console\Output\ConsoleOutput))
#14 /var/www/html/vendor/drush/drush/drush.php(139): Drush\Runtime\Runtime->run(Array)
#15 /var/www/html/vendor/drush/drush/drush(4): require('/var/www/html/v...')
#16 /var/www/html/vendor/bin/drush(120): include('/var/www/html/v...')
#17 {main}
TypeError: ReflectionClass::__construct(): Argument #1 ($objectOrClass) must be of type object|string, null given in ReflectionClass->__construct() (line 145 of /var/www/html/vendor/drush/drush/src/Runtime/LegacyServiceInstantiator.php).
 [warning] Drush command terminated abnormally.

i did basically the same in the test that lead to the code snippet i'Ve posted in the comment later. the only difference between the setup there and the setup in the issue summary and the snippet here is i've tested on drupal 10.1.x while the other snippet was from an install with drupal 10.0.9.

i'll open an issue in the automatic updates queue and also link to this issue for context.

@greg-1-anderson
Copy link
Member

"Fixed" in #5629, which will disable Automatic Update's Drush command in Drush 12. I already told them that they will need to convert to the static create() factory method, but a formal issue for tracking is probably useful.

@rpkoller
Copy link
Author

rpkoller commented Jun 6, 2023

awesome thank you! and cool, i suppose you are at drupalcon then. enjoy your time there! and i've opened an issue for tracking it: https://www.drupal.org/project/automatic_updates/issues/3365206 (and also quoted your proposed resolution)

@weitzman weitzman closed this as completed Jun 7, 2023
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