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.

Issue fork feeds-3217262

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

smustgrave created an issue. See original summary.

smustgrave’s picture

Status: Active » Needs review

Added a simple check

megachriz’s picture

Status: Needs review » Needs work

What are the steps to reproduce this issue? From the backtrace it looks like to be related to a file target. How do you have the file target configured on the mapping?

Note: the code changes are failing tests. I think the array check is added one time too many.

smustgrave’s picture

Not sure what field could be causing this. We have 3 feeds with a combo of entity references, links, etc.
Running cron fills our logs with these warnings.

Though we recently cleared our queue table of some bad feed entries there were also generating errors seen here
https://www.drupal.org/project/feeds/issues/3163897

So maybe this warning was a symptom of that error?

Take that back the warnings are still happening.

megachriz’s picture

It would be nice to see what the contents of $vars is when array_flip() is called on it. Though I expect it to be null.

Thanks for adjusting the code, but it looks like they still fail tests.

megachriz’s picture

Status: Needs work » Needs review

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 know how the bug could be reproduced though.

  • megachriz committed 364322c4 on 8.x-3.x
    Issue #3217262 by megachriz: Avoid usage of array_flip() in FeedType::...
megachriz’s picture

Status: Needs review » Closed (cannot reproduce)

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.