ValueError: array_chunk(): Argument #2 ($length) must be greater than 0 in array_chunk()

Created on 11 July 2024, about 2 months ago
Updated 27 July 2024, about 1 month ago

Problem/Motivation

I get this error in the log after installing the module.

ValueError: array_chunk(): Argument #2 ($length) must be greater than 0 in array_chunk() (line 69 of /var/www/web/modules/contrib/trash/src/TrashEntityPurger.php)

#0 /var/www/web/modules/contrib/trash/src/TrashEntityPurger.php(69): array_chunk(Array, NULL)
#1 /var/www/web/modules/contrib/trash/src/TrashEntityPurger.php(90): Drupal\trash\TrashEntityPurger->populatePurgeQueue('file')
#2 /var/www/web/modules/contrib/trash/trash.module(323): Drupal\trash\TrashEntityPurger->cronPurge()
#3 /var/www/web/core/lib/Drupal/Core/Cron.php(335): trash_cron()
#4 /var/www/web/core/lib/Drupal/Core/Extension/ModuleHandler.php(388): Drupal\Core\Cron->Drupal\Core\{closure}(Object(Closure), 'trash')
#5 /var/www/web/core/lib/Drupal/Core/Cron.php(318): Drupal\Core\Extension\ModuleHandler->invokeAllWith('cron', Object(Closure))
#6 /var/www/web/core/lib/Drupal/Core/Cron.php(159): Drupal\Core\Cron->invokeCronHandlers()
#7 /var/www/web/core/lib/Drupal/Core/ProxyClass/Cron.php(75): Drupal\Core\Cron->run()
#8 /var/www/web/core/modules/automated_cron/src/EventSubscriber/AutomatedCron.php(65): Drupal\Core\ProxyClass\Cron->run()
#9 [internal function]: Drupal\automated_cron\EventSubscriber\AutomatedCron->onTerminate(Object(Symfony\Component\HttpKernel\Event\TerminateEvent), 'kernel.terminat...', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))
#10 /var/www/web/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(111): call_user_func(Array, Object(Symfony\Component\HttpKernel\Event\TerminateEvent), 'kernel.terminat...', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))
#11 /var/www/vendor/symfony/http-kernel/HttpKernel.php(115): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object(Symfony\Component\HttpKernel\Event\TerminateEvent), 'kernel.terminat...')
#12 /var/www/web/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(63): Symfony\Component\HttpKernel\HttpKernel->terminate(Object(Symfony\Component\HttpFoundation\Request), Object(Symfony\Component\HttpFoundation\JsonResponse))
#13 /var/www/web/core/lib/Drupal/Core/DrupalKernel.php(688): Drupal\Core\StackMiddleware\StackedHttpKernel->terminate(Object(Symfony\Component\HttpFoundation\Request), Object(Symfony\Component\HttpFoundation\JsonResponse))
#14 /var/www/web/index.php(22): Drupal\Core\DrupalKernel->terminate(Object(Symfony\Component\HttpFoundation\Request), Object(Symfony\Component\HttpFoundation\JsonResponse))
#15 {main}
๐Ÿ› Bug report
Status

Fixed

Version

3.0

Component

Code

Created by

๐Ÿ‡บ๐Ÿ‡ธUnited States CNDexter

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @CNDexter
  • Status changed to Needs review about 2 months ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia sarwan

    Hi @CNDexter,

    I have fixed this issue "ValueError: array_chunk(): Argument #2 ($length) must be greater than 0 in array_chunk()" and also attached patch ,
    please review and verify .

  • ananya.k โ†’ made their first commit to this issueโ€™s fork.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia ayush.pandey

    @sarwan_verma โ†’ , Can you please elaborate, how you reproduced this issue specifically, and if possible, any screenshots. For Drupal 10.3, the issue is not reproducible, with or without any content in the database. Installing the module works swiftly.

  • ๐Ÿ‡ท๐Ÿ‡ดRomania amateescu

    Here's a patch that sets a default value for the entity_update_batch_size setting, which might not exist in a site. Also added a safety check if there are no items to purge.

    However, the auto_purge.enabled trash setting is false initially, and the only entity type that's enabled by default is node.

    @CNDexter, are you sure that the error happened when installing the module? And if so, can you check if the file entity type already has a deleted field?

  • Status changed to Postponed: needs info about 2 months ago
  • ๐Ÿ‡ท๐Ÿ‡ดRomania amateescu

    I've committed the patch in #5 to 3.x, but I'm keeping the issue open in case there are any more details that can be shared.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States CNDexter

    @sarwan_verma @amateescu @ayush.pandey this was happening after install (not during). I noticed this error happened a bit after install, likely when files started getting moved to the trash. Otherwise it installs cleanly. I'm on 10.2.5 and it looks like the patch in #5 resolves the error. Thank you so very much!

  • Status changed to Fixed about 2 months ago
  • ๐Ÿ‡ท๐Ÿ‡ดRomania amateescu

    Glad to hear that, we can close this now.

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

Production build 0.71.5 2024