Field feeds_item is unknown when looking up a taxonomy item that doesn't exist

Created on 21 January 2022, over 3 years ago
Updated 12 December 2024, 4 months ago

Problem/Motivation

There is a code error when trying to look up a taxonomy item that doesn't exist. Work around is to create the taxonomy item. The code doesn't make sense to me.

Steps to reproduce

* Create a feed
* Create content type with a taxonomy entity reference.
* Map CSV item to the taxonomy field.

InvalidArgumentException: Field feeds_item is unknown. in /web/core/lib/Drupal/Core/Entity/ContentEntityBase.php:587 Stack trace: #0 /web/core/lib/Drupal/Core/Entity/ContentEntityBase.php(568): Drupal\Core\Entity\ContentEntityBase->getTranslatedField() #1 /web/modules/contrib/feeds/src/Feeds/Target/EntityReference.php(126): Drupal\Core\Entity\ContentEntityBase->get() #2 /web/modules/patched/feeds_para_mapper/src/Importer.php(188): Drupal\feeds\Feeds\Target\EntityReference->setTarget() #3 /web/modules/patched/feeds_para_mapper/src/Importer.php(119): Drupal\feeds_para_mapper\Importer->setValue() #4 /web/modules/patched/feeds_para_mapper/src/Feeds/Target/WrapperTarget.php(166): Drupal\feeds_para_mapper\Importer->import() #5 /web/modules/contrib/feeds/src/Feeds/Processor/EntityProcessorBase.php(1092): Drupal\feeds_para_mapper\Feeds\Target\WrapperTarget->setTarget() #6 /web/modules/contrib/feeds/src/Feeds/Processor/EntityProcessorBase.php(178): Drupal\feeds\Feeds\Processor\EntityProcessorBase->map() #7 /web/modules/contrib/feeds/src/EventSubscriber

Proposed resolution

I am using paragraph mapper and the entity is a Paragraph, not the the Feed. I don't understand how feed_item becomes a field on the feed

web/modules/contrib/feeds/src/Feeds/Target/EntityReference.php

#124

   catch (ReferenceNotFoundException $e) {
        // The referenced entity is not found. We need to enforce Feeds to try
        // to import the same item again on the next import.
        // Feeds stores a hash of every imported item in order to make the
        // import process more efficient by ignoring items it has already seen.
        // In this case we need to destroy the hash in order to be able to
        // import the reference on a next import.
        $entity->get('feeds_item')->hash = NULL;
        $feed->getState(StateInterface::PROCESS)->setMessage($e->getFormattedMessage(), 'warning', TRUE);

The rest of the code checks for feeds_item

    if (array_key_exists('feeds_item', $this->getPotentialFields())) {
      $config['feeds_item'] = FALSE;
    }

I suggest that this is part of the fix? Probably all of it, if the hash is not set because the item has not been imported before.

It is the same in ConfigEntityReference.

The EntityProcessorBase test case assumes the node has this field. It does not look widely used? This field is added to the content entity as part of the processing?

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Component

Code

Created by

🇦🇺Australia interlated

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.

  • 🇬🇧United Kingdom jacobupal Leeds

    I don't know if this was the problem for OP, but I had this same error when I created the feed type by importing a config with drush.

    When you you create a feed type manually, it creates the feed_item field on the content type.

    However, importing the config with drush doesn't do anything to the content type.

    To resolve this I went to the settings page for the problematic feed type and just hit save, this seems to have generated the field and fixed the problem. The importer was then able to run successfully.

  • 🇳🇱Netherlands megachriz

    @jacobupal
    The feed type indeed cannot work correctly if you don't have the feed_item field. So perhaps the bug is here that the feed type doesn't have declared a dependency on the feed_item field.

  • 🇬🇧United Kingdom jacobupal Leeds

    Would that dependency force the feeds_item field to be created when you import a config, or just prevent the import?

  • 🇳🇱Netherlands megachriz

    @jacobupal
    Prevented. If a feed type would have a dependency on the feeds_item field, you cannot import the feed type configuration if the feeds_item field does not exist. So in that case you would also need to import the feeds_item field configuration.

  • 🇬🇧United Kingdom jacobupal Leeds

    Got it. It's a shame that such a fix would prevent my workaround!

  • 🇳🇱Netherlands megachriz

    @jacobupal
    Well, there is more config in Drupal that you cannot import if other config does not exist. And you could still technically apply the workaround if you remove the dependency line from the config file.

  • 🇬🇧United Kingdom jacobupal Leeds

    Good to know!

Production build 0.71.5 2024