Problem/Motivation

When setting the term name as unique target, Feeds fails to restrict to search for an existing entity within the same vocabulary.

This can cause the following error:

InvalidArgumentException: Field feeds_item is unknown. in Drupal\Core\Entity\ContentEntityBase->getTranslatedField()

Proposed resolution

When looking for an entity with the same name, restrict the search to entities within the same bundle (if the entity type in question supports bundles).

Original report by ksc

Two Problems: Server Error 500 - Field feeds_item is unknown / partial import

PHP: 5.6.33 (XAMPP Windows)
Drupal: 8.5.3

Feeds: 8.x-3.0-alpha1
Tamper: 8.x-1.x-dev updated 25 May 2018
Feeds Tamper: 8.x-2.x-dev updated 25 May 2018

Fetcher: Upload
Parser: CSV
Processor: Term (Taxonomy)
Processor settings: Update excisting ...

Fields:
- Term (set as unique)
- Plain Text
- Taxonomy Reference Field (Tamper: Break up sequenced data into an array)
- Taxonomy Reference Field (Tamper: Break up sequenced data into an array)
- Description

I have 611 records in cvs to import.
With the first import 497 records got imported, no error messages. No idea why only 497 - I checked the CSV with notepad++ but nothing special in lines 497 - 499, seem to be ok.

With a second try to import the csv file the follwoing message shows up:

"Ein AJAX-HTTP-Fehler ist aufgetreten. (an error occured)
HTTP-Rückgabe-Code: 500
Im Folgenden finden Sie Debugging-Informationen.
Pfad: /.../batch?id=134&op=do_nojs&op=do
Statustext: 500 Service unavailable (with message)
Antworttext: ..."

The drupal error protocol lists the following error:

"InvalidArgumentException: Field feeds_item is unknown. in Drupal\Core\Entity\ContentEntityBase->getTranslatedField() (line 580 in C:\xampp\htdocs\...\core\lib\Drupal\Core\Entity\ContentEntityBase.php)."

I have around one thousand records more to import.

Thanks for your support! Thanks for provide this module!

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ksc created an issue. See original summary.

MegaChriz’s picture

Category: Bug report » Support request
Status: Active » Fixed

It looks like that you have accidentally removed the feeds_item field on your vocabulary. Resave the feed type and try again.

I'm considering in making the feeds_item field a base field on the entity so that you can no longer accidentally remove it and break your import. I've experimented with that idea in #2799225-14: The "hidden" plugin does not exist: Drupal\Component\Plugin\Exception\PluginNotFoundException:.

ksc’s picture

Mhm, the feeds_item field is still in the vocabulary - at least it shows up there.

When I try to edit it I get an error:

Location: .../admin/structure/taxonomy/manage/tx_indiref/overview/fields/taxonomy_term.tx_indiref.feeds_item
Message: Drupal\Component\Plugin\Exception\PluginNotFoundException: The "hidden" plugin does not exist. in Drupal\Core\Plugin\DefaultPluginManager->doGetDefinition() (line 52 in ...\core\lib\Drupal\Component\Plugin\Discovery\DiscoveryTrait.php).

The curious thing is, that the first import went relatively well - 497 records of 611. (Why only 497?)
And the error (title of this issue) came when I tried to import again. Between two imports I didn´t touch the fields in the vocabulary, I just changed the filename of the csv-file for import.

ksc’s picture

I´ll uninstall feeds (feeds tamper + tamper) and install it again and try to reproduce the problem - I started with a feeds dev version from some month ago.
I´ll let you know what happens.

By the way: feeds module can only be uninstalled when deleting everything backwards: the feeds, the tamper definitions, the assingments, and the feeds-types. Otherwise it can´t be uninstalled because of excisting fields.

MegaChriz’s picture

Yes, it's quite a hassle to uninstall Feeds. It could probably be made a bit easier if the feeds_item field was a base field. But do indeed individual tamper definitions need to be removed first too? I would think it would be enough to just delete the feed types and then the tamper plugin instances would be deleted with them. This is because the tamper plugin instances are saved on the feed type itself.

Note: on the uninstall modules page there is a link to delete all feed entities.

ksc’s picture

So after uninstall, new install etc what happened is:

Created 1 items
Updated 496 items

(total 611 records)

and it ended with the same error:
Server Error 500

protocol:
InvalidArgumentException: Field feeds_item is unknown. in Drupal\Core\Entity\ContentEntityBase->getTranslatedField() (Zeile 580 in C:\xampp\htdocs\medikartei-8-1\core\lib\Drupal\Core\Entity\ContentEntityBase.php).

ksc’s picture

Uninstalling feeds - your question about uninstall tamper items:
I´m not sure about this point. At least I had to delete the assignments within the feeds types and then delete the types itself.

The link to delete all feed entities shows up now - it was not here before.

MegaChriz’s picture

Status: Fixed » Postponed (maintainer needs more info)

Hm, I think this is caused by the following issue: #2820548: Fatal error when triggering Feeds via cron .

If you deleted a feed type for which an import is still in progress, the import task remains in the queue. And when the import task runs, it cannot find the feed type, fails with an error similar as above and holds up other import tasks in the queue. Can you try the patch from #2820548-15: Fatal error when triggering Feeds via cron and see if that fixes your issue? The error reported in the other issue is different though (Call to a member function hasTranslation() on null), so maybe it doesn't help.

MegaChriz’s picture

Or did you perform an import using the UI?

MegaChriz’s picture

Wait, you did. Else you would not have gotten an AJAX error.

Can you try to reproduce the issue on a fresh install of Drupal? To rule out possible module conflicts?

ksc’s picture

Yes, I used the UI.
OK, I´ll try it with a fresh installation. Will take a while - I don´t have and know the smart developer tools. :-)

ksc’s picture

So: with a fresh installation 8.5.3 (I have chosen German language):

Items imported: 497
(all correct)

Same error: Ajax Server Error 500

InvalidArgumentException: Field feeds_item is unknown. in Drupal\Core\Entity\ContentEntityBase->getTranslatedField() (Zeile 580 in C:\xampp\htdocs\drupal-8.5.3\core\lib\Drupal\Core\Entity\ContentEntityBase.php).

MegaChriz’s picture

That's interesting. Does the same error occur if you only import lines 497 - 499 from the CSV file?

This bug looks like one that would be hard to reproduce without knowing how your configuration exactly looks like and what content you are trying to import. If you can share your configuration and a file that triggers the error, that would be helpful. Sharing configuration can be done with a feature module. Make sure that the feature module contains the following:

  • The Feed type;
  • The vocabulary selected on the processor;
  • Fields used on your vocabulary;
  • Field storage items of your fields;
  • Optionally other configuration that is related.

Tamper plugin instances are stored on the feed type in D8.

ksc’s picture

Aha.
I imported lines 497 - 501 from the CSV file.
One record/item got imported - then Error 500.

I checked the csv-file with a hexeditor but can´t find anything unusual - just German Umlaute like ä,ö etc and + () which occur also in previous records/items.

Attached the configuration and the csv-file. Hope, I dexported the right configurations.
I´m curious what you´ll find out. :-)

MegaChriz’s picture

Title: Server Error 500 - Field feeds_item is unknown » When looking for an entity with the same name, restrict search to entities within the same bundle
Category: Support request » Bug report
Issue summary: View changes
Status: Postponed (maintainer needs more info) » Active

@ksc
I took me a few days before I could find time to look at this. I've found the cause of the issue! The issue is as follows:

  1. 'Suchbegriff -> Term name' is set as unique target.
  2. You importing terms to other taxonomies as well.
  3. At a certain point the term 'Schmerzen' gets added to the vocabulary 'Zuordnung funktional'.
  4. When Feeds comes across the term 'Schmerzen' in the column 'Suchbegriff', it tries to find a term with the same name.
  5. Feeds happens to not restrict that search to the vocabulary it imports terms for and finds a term called 'Schmerzen' in the vocabulary 'Zuordnung funktional'. This vocabulary does not have a feeds_item field and thus an error happens.

Conclusion: there is a bug in Feeds: when setting the term name as unique target, Feeds fails to restrict to search for an existing entity within the same vocabulary.

Possible workaround: Map 'Suchbegriff' also to 'Feeds item: Item GUID' and use that as unique target instead.

ksc’s picture

OK, thanks a lot :-)
This was a tricky one. So I know, what kind o f data I have to avoid at the moment.

Just a remark to the suggested workaround: when using feeds_item: Item GUID as unique, the vocabulary or content type needs to be empty, otherwise one could get double entries.

MegaChriz’s picture

@ksc
You are right that if you add mapping to 'Feeds item: Item GUID' and set that as unique right away, the vocabulary needs to be empty as it else would lead to duplicates.

You could however add the mapping to 'Feeds item: Item GUID', keep 'Term name' as the unique target and import all records again that could be imported without errors. Then all imported terms will have a value for 'Feeds item: Item GUID'. You can then switch over to use 'Feeds item: Item GUID' as unique target and duplicates will be avoided.

Omar Alahmed’s picture

Actually, I have the same problem with two node importers, both of them has the same GUID integer value for different two fields and different bundles.

This is because the following line of code in existingEntityId() returns a conflict GUID because it doesn't restrict the query to the bundle:

$entity_id = $plugin->getUniqueValue($feed, $mapping['target'], $key, $item->get($mapping['map'][$key]));

And sometimes it returns a warning 'Field field_name_goes_here is unknown' when it finds a GUID of the other content type and not match the importer bundle or content type.

The following patch will add an extra condition by the bundle key and bundle value and it works in my case.

Omar Alahmed’s picture

Version: 8.x-3.0-alpha1 » 8.x-3.0-alpha4
Status: Active » Needs review

Status: Needs review » Needs work
chadrossouw’s picture

I had a similar problem, when trying to update nodes using their title as a unique identifier. The patch worked to resolve my issue. Commenting here to say thank you!

carolpettirossi’s picture

Status: Needs work » Reviewed & tested by the community

I was facing the same issue when importing taxonomies. The feed type has the "Update existing taxonomy terms" flagged and "Name" as Unique lookup.

I've applied the patch provided by Omar on #18 solved my issue.

Thanks,
Carol

MegaChriz’s picture

  • MegaChriz committed 76eb7a3 on 8.x-3.x
    Issue #2975826 by MegaChriz, Omar Alahmed, ksc, carolpettirossi,...
MegaChriz’s picture

Status: Needs review » Fixed

Tests are passing now and the test only patch demonstrates the issue.

Committed #23.

MegaChriz’s picture

Crediting the reviewers.

Status: Fixed » Closed (fixed)

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