Error on config import during external entity field creation

Created on 1 April 2020, about 4 years ago
Updated 25 January 2023, over 1 year ago

For some reason during external entity field storage creation on config import, the external entity module is trying to load the external entities, then mapping the fields, an in that moment the following error is being thrown:

Call to a member function getType() on null in /var/www/html/web/modules/contrib/external_entities/src/ExternalEntityStorage.php on line 337 #0 /var/www/html/web/modules/contrib/external_entities/src/ExternalEntityStorage.php(245): Drupal\external_entities\ExternalEntityStorage->mapFromRawStorageData(Array)
#1 /var/www/html/web/modules/contrib/external_entities/src/ExternalEntityStorage.php(201): Drupal\external_entities\ExternalEntityStorage->getFromExternalStorage(Array)
#2 /var/www/html/web/core/lib/Drupal/Core/Entity/EntityStorageBase.php(300): Drupal\external_entities\ExternalEntityStorage->doLoadMultiple(Array)
#3 /var/www/html/web/modules/contrib/search_api/src/Plugin/search_api/datasource/ContentEntity.php(854): Drupal\Core\Entity\EntityStorageBase->loadMultiple(Array)
#4 /var/www/html/web/modules/contrib/search_api/src/Plugin/search_api/datasource/ContentEntity.php(698): Drupal\search_api\Plugin\search_api\datasource\ContentEntity->getPartialItemIds(0)
#5 /var/www/html/web/modules/contrib/search_api/src/Task/IndexTaskManager.php(151): Drupal\search_api\Plugin\search_api\datasource\ContentEntity->getItemIds(0)
#6 [internal function]: Drupal\search_api\Task\IndexTaskManager->trackItems(Object(Drupal\search_api\Task\TaskEvent), 'search_api.task...', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))
#7 /var/www/html/web/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(111): call_user_func(Array, Object(Drupal\search_api\Task\TaskEvent), 'search_api.task...', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))
#8 /var/www/html/web/modules/contrib/search_api/src/Task/TaskManager.php(195): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('search_api.task...', Object(Drupal\search_api\Task\TaskEvent))
#9 /var/www/html/web/modules/contrib/search_api/src/Task/TaskManager.php(247): Drupal\search_api\Task\TaskManager->executeSpecificTask(Object(Drupal\search_api\Entity\Task))
#10 /var/www/html/web/modules/contrib/search_api/src/Task/IndexTaskManager.php(219): Drupal\search_api\Task\TaskManager->executeAllTasks(Array)
#11 /var/www/html/web/modules/contrib/search_api/src/Entity/Index.php(1405): Drupal\search_api\Task\IndexTaskManager->addItemsAll(Object(Drupal\search_api\Entity\Index))
#12 /var/www/html/web/modules/contrib/search_api/src/Entity/SearchApiConfigEntityStorage.php(51): Drupal\search_api\Entity\Index->postSave(Object(Drupal\search_api\Entity\SearchApiConfigEntityStorage), false)
#13 /var/www/html/web/core/lib/Drupal/Core/Entity/EntityStorageBase.php(460): Drupal\search_api\Entity\SearchApiConfigEntityStorage->doPostSave(Object(Drupal\search_api\Entity\Index), false)
#14 /var/www/html/web/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php(263): Drupal\Core\Entity\EntityStorageBase->save(Object(Drupal\search_api\Entity\Index))
#15 /var/www/html/web/core/lib/Drupal/Core/Entity/EntityBase.php(395): Drupal\Core\Config\Entity\ConfigEntityStorage->save(Object(Drupal\search_api\Entity\Index))
#16 /var/www/html/web/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php(613): Drupal\Core\Entity\EntityBase->save()
#17 /var/www/html/web/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php(364): Drupal\Core\Config\Entity\ConfigEntityBase->save()
#18 /var/www/html/web/core/lib/Drupal/Core/Config/ConfigImporter.php(997): Drupal\Core\Config\Entity\ConfigEntityStorage->importCreate('search_api.inde...', Object(Drupal\Core\Config\Config), Object(Drupal\Core\Config\Config))
#19 /var/www/html/web/core/lib/Drupal/Core/Config/ConfigImporter.php(783): Drupal\Core\Config\ConfigImporter->importInvokeOwner('', 'create', 'search_api.inde...')
#20 /var/www/html/web/core/lib/Drupal/Core/Config/ConfigImporter.php(610): Drupal\Core\Config\ConfigImporter->processConfiguration('', 'create', 'search_api.inde...')
#21 /var/www/html/web/core/lib/Drupal/Core/Config/ConfigImporter.php(514): Drupal\Core\Config\ConfigImporter->processConfigurations(Array)
#22 /var/www/html/vendor/drush/drush/src/Drupal/Commands/config/ConfigImportCommands.php(239): Drupal\Core\Config\ConfigImporter->doSyncStep('processConfigur...', Array)
#23 /var/www/html/vendor/drush/drush/includes/drush.inc(223): Drush\Drupal\Commands\config\ConfigImportCommands->doImport(Object(Drupal\Core\Config\StorageComparer))
#24 /var/www/html/vendor/drush/drush/includes/drush.inc(214): drush_call_user_func_array(Array, Array)
#25 /var/www/html/vendor/drush/drush/src/Drupal/Commands/config/ConfigImportCommands.php(211): drush_op(Array, Object(Drupal\Core\Config\StorageComparer))
#26 [internal function]: Drush\Drupal\Commands\config\ConfigImportCommands->import('sync', Array)
#27 /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(257): call_user_func_array(Array, Array)
#28 /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(212): Consolidation\AnnotatedCommand\CommandProcessor->runCommandCallback(Array, Object(Consolidation\AnnotatedCommand\CommandData))
#29 /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(178): Consolidation\AnnotatedCommand\CommandProcessor->validateRunAndAlter(Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
#30 /var/www/html/vendor/consolidation/annotated-command/src/AnnotatedCommand.php(302): Consolidation\AnnotatedCommand\CommandProcessor->process(Object(Symfony\Component\Console\Output\ConsoleOutput), Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
#31 /var/www/html/vendor/symfony/console/Command/Command.php(255): Consolidation\AnnotatedCommand\AnnotatedCommand->execute(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#32 /var/www/html/vendor/symfony/console/Application.php(1005): Symfony\Component\Console\Command\Command->run(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#33 /var/www/html/vendor/symfony/console/Application.php(255): Symfony\Component\Console\Application->doRunCommand(Object(Consolidation\AnnotatedCommand\AnnotatedCommand), Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#34 /var/www/html/vendor/symfony/console/Application.php(148): Symfony\Component\Console\Application->doRun(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#35 /var/www/html/vendor/drush/drush/src/Runtime/Runtime.php(118): Symfony\Component\Console\Application->run(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#36 /var/www/html/vendor/drush/drush/src/Runtime/Runtime.php(49): Drush\Runtime\Runtime->doRun(Array, Object(Symfony\Component\Console\Output\ConsoleOutput))
#37 /var/www/html/vendor/drush/drush/drush.php(72): Drush\Runtime\Runtime->run(Array)
#38 /var/www/html/vendor/drush/drush/includes/preflight.inc(18): require('/var/www/html/v...')
#39 phar:///usr/local/bin/drush/bin/drush.php(141): drush_main()
#40 /usr/local/bin/drush(10): require('phar:///usr/loc...')
#41 {main}
Error: Call to a member function getType() on null in Drupal\external_entities\ExternalEntityStorage->mapFromRawStorageData() (line 337 of /var/www/html/web/modules/contrib/external_entities/src/ExternalEntityStorage.php).

The reason is that the field definition does not exists yet because it is being created on that moment. Here is the code responsible

protected function mapFromRawStorageData(array $data) {
    if (!$data) {
      return [];
    }

    $field_definitions = $this
      ->entityFieldManager
      ->getFieldDefinitions($this->getEntityTypeId(), $this->getEntityTypeId());
    $values = [];
    foreach ($data as $id => $raw_data) {
      $values[$id] = [];

      foreach ($this->getExternalEntityType()->getFieldMappings() as $field_name => $properties) {
...
       if (in_array($field_definition->getType(), $date_fields)) {

the function getFromExternalStorage() is tte only place where the function mapFromRawStorageData() is called, and getFromExternalStorage() is called only from doLoadMultiple(). so we could just skip this operation during configuration synchronization.

πŸ› Bug report
Status

Postponed: needs info

Version

2.0

Component

Code

Created by

πŸ‡ͺπŸ‡ΈSpain akalam

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

Comments & Activities

Not all content is available!

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

  • πŸ‡³πŸ‡±Netherlands pgrond

    Is this still an issue? I see that after some refactoring ->getType() is not called anymore in mapFromRawStorageData().

    Can you check if this still is relevant?

Production build 0.69.0 2024