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

Error when modules get installed via config:import after PR #5714 (locale and language config collections) #5838

Closed vever001 closed 8 months ago

vever001 commented 11 months ago

Describe the bug After updating to drush 12, and PR https://github.com/drush-ops/drush/pull/5714 included in drush 12.1.3 specifically, it looks like there can be a side effect with language config collections in some situations.

I am getting this error on a multilingual site during config:import:

[warning] Trying to access array offset on value of type null ConfigImporter.php:353

TypeError: array_diff(): Argument #2 must be of type array, null given in web/core/lib/Drupal/Core/Config/ConfigImporter.php on line 353 #0 web/core/lib/Drupal/Core/Config/ConfigImporter.php(353): array_diff() See full log below.

At the beginning of config:import, locale_system_update gets called if modules need to be enabled. This can cause some new config collections to be added (during the batch process that https://github.com/drush-ops/drush/pull/5714 added) and if so, leads to the error above. So initially, we need a language but without any corresponding config collection records (in the config table).

This may not be an issue with drush itself but drupal core.

To Reproduce In my case I have an mk language in drupal and no corresponding language.mk config collection (in the config table) initially. Then when running config:import, devel gets enabled which imports config translations. See full log below.

This may not be easy to reproduce from a clean setup... but I'll try to do it when I have some time.

Expected behavior No error

Actual behavior An error

Workaround I noticed calling locale_config_batch_update_components before config:import runs (in a post-update hook for example) prevents the issue to happen because it will create several records with the language.mk collection in config table (but it is not guaranteed to do so).

System Configuration

Q A
Drush version? >= 12.1.3 (with PR https://github.com/drush-ops/drush/pull/5714 included)
Drupal version? 10.1.7
PHP version 8.1
OS? Linux

Additional information Here is the relevant output from config:import:

// Import the listed configuration changes?: yes.                              

>  [notice] Synchronized extensions: uninstall allowed_formats.
>  [notice] Synchronized extensions: uninstall f_pt_cta.
>  [notice] Synchronized extensions: install stage_file_proxy.
>  [info] Executing: /vendor/bin/drush batch-process 145 --uri=default
> > 
> >  [notice] Message: No configuration objects have been updated.
> > 
>  [notice] Synchronized extensions: install f_dev.
>  [info] Executing: /vendor/bin/drush batch-process 146 --uri=default
> > 
> >  [notice] Message: No configuration objects have been updated.
> > 
>  [notice] Synchronized extensions: install devel.
>  [info] Executing: /vendor/bin/drush batch-process 147 --uri=default
> > 
> >  [notice] Message: No configuration objects have been updated.
> > 
>  [warning] Undefined array key "language.mk" ConfigImporter.php:353
>  [warning] Trying to access array offset on value of type null ConfigImporter.php:353
> TypeError: array_diff(): Argument #2 must be of type array, null given in /web/core/lib/Drupal/Core/Config/ConfigImporter.php on line 353 #0 /web/core/lib/Drupal/Core/Config/ConfigImporter.php(353): array_diff()
> #1 /web/core/lib/Drupal/Core/Config/ConfigImporter.php(650): Drupal\Core\Config\ConfigImporter->getUnprocessedConfiguration()
> #2 /web/core/lib/Drupal/Core/Config/ConfigImporter.php(561): Drupal\Core\Config\ConfigImporter->processConfigurations()
> #3 /vendor/drush/drush/src/Commands/config/ConfigImportCommands.php(259): Drupal\Core\Config\ConfigImporter->doSyncStep()
> #4 /vendor/drush/drush/includes/drush.inc(62): Drush\Commands\config\ConfigImportCommands->doImport()
> #5 /vendor/drush/drush/includes/drush.inc(53): drush_call_user_func_array()
> #6 /vendor/drush/drush/src/Commands/config/ConfigImportCommands.php(230): drush_op()
> #7 [internal function]: Drush\Commands\config\ConfigImportCommands->import()
> #8 /vendor/consolidation/annotated-command/src/CommandProcessor.php(276): call_user_func_array()
> #9 /vendor/consolidation/annotated-command/src/CommandProcessor.php(212): Consolidation\AnnotatedCommand\CommandProcessor->runCommandCallback()
> #10 /vendor/consolidation/annotated-command/src/CommandProcessor.php(176): Consolidation\AnnotatedCommand\CommandProcessor->validateRunAndAlter()
> #11 /vendor/consolidation/annotated-command/src/AnnotatedCommand.php(391): Consolidation\AnnotatedCommand\CommandProcessor->process()
> #12 /vendor/symfony/console/Command/Command.php(326): Consolidation\AnnotatedCommand\AnnotatedCommand->execute()
> #13 /vendor/symfony/console/Application.php(1081): Symfony\Component\Console\Command\Command->run()
> #14 /vendor/symfony/console/Application.php(320): Symfony\Component\Console\Application->doRunCommand()
> #15 /vendor/symfony/console/Application.php(174): Symfony\Component\Console\Application->doRun()
> #16 /vendor/drush/drush/src/Runtime/Runtime.php(110): Symfony\Component\Console\Application->run()
> #17 /vendor/drush/drush/src/Runtime/Runtime.php(40): Drush\Runtime\Runtime->doRun()
> #18 /vendor/drush/drush/drush.php(139): Drush\Runtime\Runtime->run()
> #19 /vendor/drush/drush/drush(4): require('...')
> #20 /vendor/bin/drush(119): include('...')
> #21 {main}
TypeError: array_diff(): Argument #2 must be of type array, null given in array_diff() (line 353 of /web/core/lib/Drupal/Core/Config/ConfigImporter.php).
>  [warning] Drush command terminated abnormally.

In SiteProcess.php line 214:

  [Symfony\Component\Process\Exception\ProcessFailedException]                 
  The command "/vendor/bin/drush config:import --verbose --yes -  
  -uri=default" failed.                                                        

  Exit Code: 1(General error)
emek-lu commented 9 months ago

I have just encountered this error in our environment, and only on sites that are set to Swedish where I get the following errors:

[warning] Undefined array key "language.en" ConfigImporter.php:353
[warning] Trying to access array offset on value of type null ConfigImporter.php:353

The next time I import configuration it works without any errors, but because the error occurs the first time it disturbs our deploy process.

Is there any way to fix this without writing post-update hooks?

viunyk commented 9 months ago

Have the same problem, TypeError: array_diff(): Argument #2 must be of type array, null given in array_diff() (line 353 of /web/core/lib/Drupal/Core/Config/ConfigImporter.php)." I try to disable the module by drush cim after on UI I can see something like

Screenshot at Feb 07 16-09-35

If I run drush cima second time it works without issue

vever001 commented 8 months ago

Quick update: Running the config import from UI (at /admin/config/development/configuration) works without issue, so this looks specific to drush.

I think drush_backend_batch_process should be triggered at the very end of ConfigImportCommands::doImport (not in the middle of a sync step), similar to what happens from UI: first all configs get imported, only then batch operations run. Doing this seems to solve the issue. I'll open a PR shortly.

weitzman commented 8 months ago

Seems reasonable to me to run batch at the end, similar to how form api does it. Any thoughts @claudiu-cristea or @alexpott or @bircher?

claudiu-cristea commented 8 months ago

@weitzman @vever001 The explanation is, indeed, reasonable. As the PR doesn't have tests I'll do a manual test with the code that required #5714 plus the PR

claudiu-cristea commented 8 months ago

Tested the #5869 PR, see may comment over there.