Warning: array_flip(): Can only flip STRING and INTEGER values!

Created on 3 June 2021, almost 4 years ago
Updated 10 October 2024, 7 months ago

Problem/Motivation

When cron runs I get a ton of warnings about
Warning: array_flip(): Can only flip STRING and INTEGER values! in Drupal\Core\Entity\EntityStorageBase->loadMultiple() (line 261 of /app/wwwroot/core/lib/Drupal/Core/Entity/EntityStorageBase.php)
#0 /app/wwwroot/core/includes/bootstrap.inc(305): _drupal_error_handler_real(2, 'array_flip(): C...', '/app/wwwroot/co...', 261)
#1 [internal function]: _drupal_error_handler(2, 'array_flip(): C...', '/app/wwwroot/co...', 261, Array)
#2 /app/wwwroot/core/lib/Drupal/Core/Entity/EntityStorageBase.php(261): array_flip(Array)
#3 /app/wwwroot/core/lib/Drupal/Core/Field/EntityReferenceFieldItemList.php(46): Drupal\Core\Entity\EntityStorageBase->loadMultiple(Array)
#4 /app/wwwroot/core/modules/file/src/Plugin/Field/FieldType/FileFieldItemList.php(26): Drupal\Core\Field\EntityReferenceFieldItemList->referencedEntities()
#5 [internal function]: Drupal\file\Plugin\Field\FieldType\FileFieldItemList->postSave(false)
#6 /app/wwwroot/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php(838): call_user_func_array(Array, Array)
#7 /app/wwwroot/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php(870): Drupal\Core\Entity\ContentEntityStorageBase->invokeFieldMethod('postSave', Object(Drupal\node\Entity\Node), false)
#8 /app/wwwroot/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php(792): Drupal\Core\Entity\ContentEntityStorageBase->invokeFieldPostSave(Object(Drupal\node\Entity\Node), false)
#9 /app/wwwroot/core/lib/Drupal/Core/Entity/EntityStorageBase.php(530): Drupal\Core\Entity\ContentEntityStorageBase->invokeHook('insert', Object(Drupal\node\Entity\Node))
#10 /app/wwwroot/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php(685): Drupal\Core\Entity\EntityStorageBase->doPostSave(Object(Drupal\node\Entity\Node), false)
#11 /app/wwwroot/core/lib/Drupal/Core/Entity/EntityStorageBase.php(455): Drupal\Core\Entity\ContentEntityStorageBase->doPostSave(Object(Drupal\node\Entity\Node), false)
#12 /app/wwwroot/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php(801): Drupal\Core\Entity\EntityStorageBase->save(Object(Drupal\node\Entity\Node))
#13 /app/wwwroot/modules/contrib/feeds/src/Feeds/Processor/EntityProcessorBase.php(192): Drupal\Core\Entity\Sql\SqlContentEntityStorage->save(Object(Drupal\node\Entity\Node))
#14 /app/wwwroot/modules/contrib/feeds/src/EventSubscriber/LazySubscriber.php(110): Drupal\feeds\Feeds\Processor\EntityProcessorBase->process(Object(Drupal\feeds\Entity\Feed), Object(Drupal\feeds\Feeds\Item\DynamicItem), Object(Drupal\feeds\State))
#15 [internal function]: Drupal\feeds\EventSubscriber\LazySubscriber->Drupal\feeds\EventSubscriber\{closure}(Object(Drupal\feeds\Event\ProcessEvent), 'feeds.process', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))
#16 /app/wwwroot/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(142): call_user_func(Object(Closure), Object(Drupal\feeds\Event\ProcessEvent), 'feeds.process', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))
#17 /app/wwwroot/modules/contrib/feeds/src/Event/EventDispatcherTrait.php(38): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object(Drupal\feeds\Event\ProcessEvent), Object(Drupal\feeds\Event\ProcessEvent))
#18 /app/wwwroot/modules/contrib/feeds/src/FeedsExecutable.php(266): Drupal\feeds\FeedsExecutable->dispatchEvent('feeds.process', Object(Drupal\feeds\Event\ProcessEvent))
#19 /app/wwwroot/modules/contrib/feeds/src/FeedsExecutable.php(113): Drupal\feeds\FeedsExecutable->doProcess(Object(Drupal\feeds\Entity\Feed), Object(Drupal\feeds\Feeds\Item\DynamicItem))
#20 /app/wwwroot/modules/contrib/feeds/src/Plugin/QueueWorker/FeedRefresh.php(36): Drupal\feeds\FeedsExecutable->processItem(Object(Drupal\feeds\Entity\Feed), 'process', Array)
#21 /app/wwwroot/core/lib/Drupal/Core/Cron.php(182): Drupal\feeds\Plugin\QueueWorker\FeedRefresh->processItem(Array)
#22 /app/wwwroot/core/lib/Drupal/Core/Cron.php(147): Drupal\Core\Cron->processQueues()
#23 /app/wwwroot/core/lib/Drupal/Core/ProxyClass/Cron.php(75): Drupal\Core\Cron->run()
#24 /app/wwwroot/core/modules/system/src/Form/CronForm.php(166): Drupal\Core\ProxyClass\Cron->run()
#25 [internal function]: Drupal\system\Form\CronForm->runCron(Array, Object(Drupal\Core\Form\FormState))
#26 /app/wwwroot/core/lib/Drupal/Core/Form/FormSubmitter.php(113): call_user_func_array(Array, Array)
#27 /app/wwwroot/core/lib/Drupal/Core/Form/FormSubmitter.php(51): Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object(Drupal\Core\Form\FormState))
#28 /app/wwwroot/core/lib/Drupal/Core/Form/FormBuilder.php(593): Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object(Drupal\Core\Form\FormState))
#29 /app/wwwroot/core/lib/Drupal/Core/Form/FormBuilder.php(321): Drupal\Core\Form\FormBuilder->processForm('system_cron_set...', Array, Object(Drupal\Core\Form\FormState))
#30 /app/wwwroot/core/lib/Drupal/Core/Controller/FormController.php(73): Drupal\Core\Form\FormBuilder->buildForm(Object(Drupal\system\Form\CronForm), Object(Drupal\Core\Form\FormState))
#31 [internal function]: Drupal\Core\Controller\FormController->getContentResult(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\RouteMatch))
#32 /app/wwwroot/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array)
#33 /app/wwwroot/core/lib/Drupal/Core/Render/Renderer.php(573): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#34 /app/wwwroot/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
#35 /app/wwwroot/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array)
#36 /app/vendor/symfony/http-kernel/HttpKernel.php(158): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#37 /app/vendor/symfony/http-kernel/HttpKernel.php(80): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
#38 /app/wwwroot/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#39 /app/wwwroot/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#40 /app/wwwroot/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#41 /app/wwwroot/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#42 /app/wwwroot/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#43 /app/wwwroot/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(52): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#44 /app/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#45 /app/wwwroot/core/lib/Drupal/Core/DrupalKernel.php(706): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#46 /app/wwwroot/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))

Proposed resolution

Put a check in.

πŸ› Bug report
Status

Needs work

Version

3.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States smustgrave

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

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Merge request !198Avoid usage of array_flip(). β†’ (Merged) created by megachriz
  • πŸ‡³πŸ‡±Netherlands megachriz

    I'm digging through some old bug reports.

    I see that the double usage of array_flip() can be avoided. Instead, I think it's better to use array_search() to look for the entry from the array to remove. I still don't how the bug could be reproduced though.

  • Pipeline finished with Skipped
    6 months ago
    #327643
    • megachriz β†’ committed 364322c4 on 8.x-3.x
      Issue #3217262 by megachriz: Avoid usage of array_flip() in FeedType::...
  • πŸ‡³πŸ‡±Netherlands megachriz

    Upon further looking at the stack trace, the array_flip() error did not happen in \Drupal\feeds\Entity\FeedType::__sleep(), but in \Drupal\Core\Entity\EntityStorageBase::loadMultiple() instead:

      /**
       * {@inheritdoc}
       */
      public function loadMultiple(?array $ids = NULL) {
        $entities = [];
        $preloaded_entities = [];
    
        // Create a new variable which is either a prepared version of the $ids
        // array for later comparison with the entity cache, or FALSE if no $ids
        // were passed. The $ids array is reduced as items are loaded from cache,
        // and we need to know if it is empty for this reason to avoid querying the
        // database when all requested entities are loaded from cache.
        $flipped_ids = $ids ? array_flip($ids) : FALSE;
    

    The error looks like to be triggered by either an entity reference field or a file field. While theoritically this could come from a bug in Feeds, it is not clear if this is the case. Since this issue is over 3 years old now, I think I'm just going to close it. Feel free to reopen if you still encounter this issue and if you can provide the steps to reproduce the issue.

    Note: I did merge a change for FeedType::__sleep(), because the double usage of array_flip() was not needed.

Production build 0.71.5 2024