Problem/Motivation

When not selecting any source for a target, importing breaks with something like the following error:

TypeError: Argument 4 passed to Drupal\feeds\Plugin\Type\Target\FieldTargetBase::setTarget() must be of the type array, null given, called in /Websites/drupal/drupalsites/ukkb8/web/modules/contrib/feeds/src/Feeds/Processor/EntityProcessorBase.php on line 817 in Drupal\feeds\Plugin\Type\Target\FieldTargetBase->setTarget() (line 95 of modules/contrib/feeds/src/Plugin/Type/Target/FieldTargetBase.php).

Drupal\feeds\Plugin\Type\Target\FieldTargetBase->setTarget(Object, Object, 'field_omschrijving', NULL) (Line: 843)
Drupal\feeds\Feeds\Processor\EntityProcessorBase->map(Object, Object, Object) (Line: 155)
Drupal\feeds\Feeds\Processor\EntityProcessorBase->process(Object, Object, Object) (Line: 94)
Drupal\feeds\EventSubscriber\LazySubscriber->Drupal\feeds\EventSubscriber\{closure}(Object, 'feeds.process', Object)
call_user_func(Object, Object, 'feeds.process', Object) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('feeds.process', Object) (Line: 37)
Drupal\feeds\Plugin\QueueWorker\FeedQueueWorkerBase->dispatchEvent('feeds.process', Object) (Line: 194)
Drupal\feeds\Plugin\QueueWorker\FeedRefresh->doProcess(Object, Object) (Line: 93)
Drupal\feeds\Plugin\QueueWorker\FeedRefresh->processItem(Array) (Line: 179)
Drupal\Core\Cron->processQueues() (Line: 144)
Drupal\Core\Cron->run() (Line: 75)
Drupal\Core\ProxyClass\Cron->run() (Line: 65)
Drupal\automated_cron\EventSubscriber\AutomatedCron->onTerminate(Object, 'kernel.terminate', Object)
call_user_func(Array, Object, 'kernel.terminate', Object) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.terminate', Object) (Line: 88)
Symfony\Component\HttpKernel\HttpKernel->terminate(Object, Object) (Line: 32)
Stack\StackedHttpKernel->terminate(Object, Object) (Line: 642)
Drupal\Core\DrupalKernel->terminate(Object, Object) (Line: 22)

See my configured mappings:

The reason that this happens is that field values are not generated for targets without sources.
On ± line 783 of EntityProcessorBase an empty source is skipped:

if ($source === '') {
  // Skip empty sources.
  continue;
}

Proposed resolution

Before calling setTarget() method, check if field values for the target in question were generated first.

Patch will follow.

Comments

MegaChriz created an issue. See original summary.

megachriz’s picture

Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new3.57 KB
new4.31 KB

A tests only patch to demonstrate the issue and another patch that hopefully fixes it.

The last submitted patch, 2: feeds-empty-source-2973836-2-tests-only.patch, failed testing. View results

megachriz’s picture

I forgot to include changes to FeedTypeInterface.

The last submitted patch, 2: feeds-empty-source-2973836-2.patch, failed testing. View results

The last submitted patch, 4: feeds-empty-source-2973836-3-tests-only.patch, failed testing. View results

megachriz’s picture

StatusFileSize
new5.63 KB
new870 bytes

Fixing docs and coding standards in FeedTypeInterface.

  • MegaChriz committed d0cac0d on 8.x-3.x
    Issue #2973836 by MegaChriz: Fixed TypeError when leaving source empty...
megachriz’s picture

Status: Needs review » Fixed

Committed #7.

Status: Fixed » Closed (fixed)

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