Problem/Motivation

DownloadCountCacheProcessor uses a queue to add download count values to the `download_count_cache` table.

Since Drupal 10.2, the use of Merge::key() with an array of multiple values will cause a deprecation warning. See Merge::key() renamed to Merge::keys().

In Drupal 11, running cron following a recorded download (processing of the `download_count` queue), results in an error:

$ drush cron
AssertionError: assert(is_string($field)) in /app/web/core/lib/Drupal/Core/Database/Query/Merge.php on line 330 #0 /app/web/core/lib/Drupal/Core/Database/Query/Merge.php(330): assert(false, 'assert(is_strin...')
#1 /app/web/modules/contrib/download_count/src/Plugin/QueueWorker/DownloadCountCacheProcessor.php(26): Drupal\Core\Database\Query\Merge->key(Array)
#2 /app/web/core/lib/Drupal/Core/Cron.php(208): Drupal\download_count\Plugin\QueueWorker\DownloadCountCacheProcessor->processItem(Object(stdClass))
#3 /app/web/core/lib/Drupal/Core/Cron.php(173): Drupal\Core\Cron->processQueue(Object(Drupal\Core\Queue\DatabaseQueue), Object(Drupal\download_count\Plugin\QueueWorker\DownloadCountCacheProcessor))
#4 /app/web/core/lib/Drupal/Core/Cron.php(100): Drupal\Core\Cron->processQueues()
#5 /app/web/core/lib/Drupal/Core/ProxyClass/Cron.php(75): Drupal\Core\Cron->run()
#6 /app/vendor/drush/drush/src/Commands/core/DrupalCommands.php(58): Drupal\Core\ProxyClass\Cron->run()
#7 [internal function]: Drush\Commands\core\DrupalCommands->cron(Array)
#8 /app/vendor/consolidation/annotated-command/src/CommandProcessor.php(276): call_user_func_array(Array, Array)
#9 /app/vendor/consolidation/annotated-command/src/CommandProcessor.php(212): Consolidation\AnnotatedCommand\CommandProcessor->runCommandCallback(Array, Object(Consolidation\AnnotatedCommand\CommandData))
#10 /app/vendor/consolidation/annotated-command/src/CommandProcessor.php(175): Consolidation\AnnotatedCommand\CommandProcessor->validateRunAndAlter(Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
#11 /app/vendor/consolidation/annotated-command/src/AnnotatedCommand.php(387): Consolidation\AnnotatedCommand\CommandProcessor->process(Object(Symfony\Component\Console\Output\ConsoleOutput), Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
#12 /app/vendor/symfony/console/Command/Command.php(279): Consolidation\AnnotatedCommand\AnnotatedCommand->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#13 /app/vendor/symfony/console/Application.php(1094): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#14 /app/vendor/symfony/console/Application.php(342): Symfony\Component\Console\Application->doRunCommand(Object(Consolidation\AnnotatedCommand\AnnotatedCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#15 /app/vendor/symfony/console/Application.php(193): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#16 /app/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))
#17 /app/vendor/drush/drush/src/Runtime/Runtime.php(40): Drush\Runtime\Runtime->doRun(Array, Object(Symfony\Component\Console\Output\ConsoleOutput))
#18 /app/vendor/drush/drush/drush.php(140): Drush\Runtime\Runtime->run(Array)
#19 /app/vendor/bin/drush.php(119): include('/app/vendor/dru...')
#20 {main}
AssertionError: assert(is_string($field)) in assert() (line 330 of /app/web/core/lib/Drupal/Core/Database/Query/Merge.php).

Steps to reproduce

  1. Download an item that is tracked by Download Count.
  2. Run cron.

Proposed resolution

Update `DownloadCountCacheProcessor::processItem` to merge array keys using `keys` instead of `key`.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

amanp created an issue. See original summary.

ericgsmith’s picture

Status: Active » Needs work

Code change is good - would require declared core version in info file to be bumped to 10.2 and above

vinodhini.e made their first commit to this issue’s fork.

vinodhini.e’s picture

Hi, I've updated the core_version_requirement in the .info.yml file to support both Drupal 10.2+ and future versions, including Drupal 11. Thanks.

vinodhini.e’s picture

Status: Needs work » Needs review
xdequinze’s picture

Using keys() instead of key() fixes the error on my Drupal 11 instance at running cron.

usingsession made their first commit to this issue’s fork.

usingsession’s picture

Status: Needs review » Fixed

Fixed, thanks everyone for your work

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.