I'm trying to use drush to generate some taxonomy terms for a sandbox/development instance. This might be an error report by I'm a drush noob so I wanted to ask first.

When I run drush devel-generate:terms --bundles=tags 10 I would expect drush to generate some terms for me, instead I get an error message like this:

#10 0.555  [error]  TypeError: count(): Argument #1 ($value) must be of type Countable|array, null given in count() (line 377 of /opt/drupal/web/modules/contrib/devel/devel_generate/src/Plugin/DevelGenerate/TermDevelGenerate.php) #0 /opt/drupal/web/modules/contrib/devel/devel_generate/src/Plugin/DevelGenerate/TermDevelGenerate.php(377): count(NULL)
#10 0.555 #1 /opt/drupal/web/modules/contrib/devel/devel_generate/src/Plugin/DevelGenerate/TermDevelGenerate.php(197): Drupal\devel_generate\Plugin\DevelGenerate\TermDevelGenerate->generateTerms(Array)
#10 0.555 #2 /opt/drupal/web/modules/contrib/devel/devel_generate/src/DevelGenerateBase.php(83): Drupal\devel_generate\Plugin\DevelGenerate\TermDevelGenerate->generateElements(Array)
#10 0.555 #3 /opt/drupal/web/modules/contrib/devel/devel_generate/src/Commands/DevelGenerateCommands.php(282): Drupal\devel_generate\DevelGenerateBase->generate(Array)
#10 0.555 #4 /opt/drupal/web/modules/contrib/devel/devel_generate/src/Commands/DevelGenerateCommands.php(159): Drupal\devel_generate\Commands\DevelGenerateCommands->generate()
#10 0.555 #5 [internal function]: Drupal\devel_generate\Commands\DevelGenerateCommands->terms('10', Array)
#10 0.555 #6 /opt/drupal/vendor/consolidation/annotated-command/src/CommandProcessor.php(257): call_user_func_array(Array, Array)
#10 0.555 #7 /opt/drupal/vendor/consolidation/annotated-command/src/CommandProcessor.php(212): Consolidation\AnnotatedCommand\CommandProcessor->runCommandCallback(Array, Object(Consolidation\AnnotatedCommand\CommandData))
#10 0.555 #8 /opt/drupal/vendor/consolidation/annotated-command/src/CommandProcessor.php(176): Consolidation\AnnotatedCommand\CommandProcessor->validateRunAndAlter(Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
#10 0.555 #9 /opt/drupal/vendor/consolidation/annotated-command/src/AnnotatedCommand.php(311): Consolidation\AnnotatedCommand\CommandProcessor->process(Object(Symfony\Component\Console\Output\ConsoleOutput), Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
#10 0.555 #10 /opt/drupal/vendor/symfony/console/Command/Command.php(255): Consolidation\AnnotatedCommand\AnnotatedCommand->execute(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#10 0.555 #11 /opt/drupal/vendor/symfony/console/Application.php(1027): Symfony\Component\Console\Command\Command->run(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#10 0.555 #12 /opt/drupal/vendor/symfony/console/Application.php(273): Symfony\Component\Console\Application->doRunCommand(Object(Consolidation\AnnotatedCommand\AnnotatedCommand), Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#10 0.555 #13 /opt/drupal/vendor/symfony/console/Application.php(149): Symfony\Component\Console\Application->doRun(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#10 0.555 #14 /opt/drupal/vendor/drush/drush/src/Runtime/Runtime.php(118): Symfony\Component\Console\Application->run(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#10 0.555 #15 /opt/drupal/vendor/drush/drush/src/Runtime/Runtime.php(49): Drush\Runtime\Runtime->doRun(Array, Object(Symfony\Component\Console\Output\ConsoleOutput))
#10 0.555 #16 /opt/drupal/vendor/drush/drush/drush.php(72): Drush\Runtime\Runtime->run(Array)
#10 0.555 #17 /opt/drupal/vendor/drush/drush/drush(4): require('/opt/drupal/ven...')
#10 0.555 #18 {main}.
#10 0.555 TypeError: count(): Argument #1 ($value) must be of type Countable|array, null given in /opt/drupal/web/modules/contrib/devel/devel_generate/src/Plugin/DevelGenerate/TermDevelGenerate.php on line 377 #0 /opt/drupal/web/modules/contrib/devel/devel_generate/src/Plugin/DevelGenerate/TermDevelGenerate.php(377): count(NULL)
#10 0.555 #1 /opt/drupal/web/modules/contrib/devel/devel_generate/src/Plugin/DevelGenerate/TermDevelGenerate.php(197): Drupal\devel_generate\Plugin\DevelGenerate\TermDevelGenerate->generateTerms(Array)
#10 0.555 #2 /opt/drupal/web/modules/contrib/devel/devel_generate/src/DevelGenerateBase.php(83): Drupal\devel_generate\Plugin\DevelGenerate\TermDevelGenerate->generateElements(Array)
#10 0.555 #3 /opt/drupal/web/modules/contrib/devel/devel_generate/src/Commands/DevelGenerateCommands.php(282): Drupal\devel_generate\DevelGenerateBase->generate(Array)
#10 0.555 #4 /opt/drupal/web/modules/contrib/devel/devel_generate/src/Commands/DevelGenerateCommands.php(159): Drupal\devel_generate\Commands\DevelGenerateCommands->generate()
#10 0.555 #5 [internal function]: Drupal\devel_generate\Commands\DevelGenerateCommands->terms('10', Array)
#10 0.555 #6 /opt/drupal/vendor/consolidation/annotated-command/src/CommandProcessor.php(257): call_user_func_array(Array, Array)
#10 0.555 #7 /opt/drupal/vendor/consolidation/annotated-command/src/CommandProcessor.php(212): Consolidation\AnnotatedCommand\CommandProcessor->runCommandCallback(Array, Object(Consolidation\AnnotatedCommand\CommandData))
#10 0.555 #8 /opt/drupal/vendor/consolidation/annotated-command/src/CommandProcessor.php(176): Consolidation\AnnotatedCommand\CommandProcessor->validateRunAndAlter(Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
#10 0.555 #9 /opt/drupal/vendor/consolidation/annotated-command/src/AnnotatedCommand.php(311): Consolidation\AnnotatedCommand\CommandProcessor->process(Object(Symfony\Component\Console\Output\ConsoleOutput), Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
#10 0.555 #10 /opt/drupal/vendor/symfony/console/Command/Command.php(255): Consolidation\AnnotatedCommand\AnnotatedCommand->execute(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#10 0.555 #11 /opt/drupal/vendor/symfony/console/Application.php(1027): Symfony\Component\Console\Command\Command->run(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#10 0.555 #12 /opt/drupal/vendor/symfony/console/Application.php(273): Symfony\Component\Console\Application->doRunCommand(Object(Consolidation\AnnotatedCommand\AnnotatedCommand), Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#10 0.555 #13 /opt/drupal/vendor/symfony/console/Application.php(149): Symfony\Component\Console\Application->doRun(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#10 0.555 #14 /opt/drupal/vendor/drush/drush/src/Runtime/Runtime.php(118): Symfony\Component\Console\Application->run(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#10 0.555 #15 /opt/drupal/vendor/drush/drush/src/Runtime/Runtime.php(49): Drush\Runtime\Runtime->doRun(Array, Object(Symfony\Component\Console\Output\ConsoleOutput))
#10 0.555 #16 /opt/drupal/vendor/drush/drush/drush.php(72): Drush\Runtime\Runtime->run(Array)
#10 0.555 #17 /opt/drupal/vendor/drush/drush/drush(4): require('/opt/drupal/ven...')
#10 0.555 #18 {main}
#10 0.555 TypeError: count(): Argument #1 ($value) must be of type Countable|array, null given in count() (line 377 of /opt/drupal/web/modules/contrib/devel/devel_generate/src/Plugin/DevelGenerate/TermDevelGenerate.php).
#10 0.560  [warning] Drush command terminated abnormally.

Dockerfile to reproduce:

FROM drupal:9.1.0

RUN composer require -n \
  drush/drush:10.3.6 \
  drupal/devel:4.0.1

RUN apt-get update; apt-get install -y sqlite3
RUN mkdir /db; chown www-data:www-data /db
USER www-data

RUN cd /opt/drupal && drush site-install -y \
    --db-url=sqlite:///db/drupal.sqlite \
    --db-su=root \
    --db-su-pw=password \
    --account-name=admin \
    --account-pass=pass
USER root

RUN drush en -y devel devel_generate
RUN drush devel-generate:terms --bundles=tags 10

What makes me suspicious that I've done something wrong is the "Argument #1 ($value) must be of type Countable|array, null given" message. Have I missed an argument?

I looked at the output of drush devel-generate:terms --help doesn't seem to suggest I've done anything wrong;

Create terms in specified vocabulary.

Arguments:
  [num] Number of terms to generate. [default: 50]

Options:
  --kill                        Delete all terms in these vocabularies before generating new ones.
  --bundles[=BUNDLES]           A comma-delimited list of machine names for the vocabularies where terms will be created.
  --feedback[=FEEDBACK]         An integer representing interval for insertion rate logging. [default: 1000]
  --languages[=LANGUAGES]       A comma-separated list of language codes
  --translations[=TRANSLATIONS] A comma-separated list of language codes for translations.
  --min-depth[=MIN-DEPTH]       The minimum depth of hierarchy for the new terms. [default: 1]
  --max-depth[=MAX-DEPTH]       The maximum depth of hierarchy for the new terms. [default: 4]

Aliases: gent, devel-generate-terms
有帮助吗?

解决方案

Seems like the version of devel_generate you're using isn't fully compatible with PHP 8.0.

This issue fixed the problem: https://gitlab.com/drupalspoons/devel/-/issues/356

Replacing drupal/devel:4.0.1 in the docker file with the dev version containing the patch (drupal/devel:4.x-dev#c8d48e2dab1d92a74fd17b5a91d005476e91b9b0) resolves the issue.

许可以下: CC-BY-SA归因
scroll top