Migrating more than 1 entity reference field instance fails

Created on 22 October 2018, about 6 years ago
Updated 1 February 2023, almost 2 years ago

Problem/Motivation

In Drupal 7, the entityreference module allowed to create multiple field instances of the same field. The migration here "works" but then any time an entity without any data attempts to set an entity reference value an InvalidArgumentException is thrown in ContentEntityBase.

InvalidArgumentException: Field <field name> is unknown.

A comparison between getting field definitions directly from entity_field.manager reveals that the field does in fact exist on the bundle, but getting the field definition on the entity itself fails. I found that if I reset the field definitions before the exception, then it tries to go further, but runs into a similar exception in typed_data_manager.

Furthermore this is only an issue for one of the bundles. The other bundle works fine.

Steps to reproduce (as detailed in a test-only patch):

  1. Add field_reference_3 field_config
  2. Add field_reference_3 field_config_instance to both article and forum node bundles.
  3. Run the appropriate migrations.
  4. Load node 2 (an article node) e.g. $node = Node::load(2);
  5. Attempt to set an initial reference e.g. $node->set('field_reference_3', [5]); or $node->get('field_reference_3')->appendItem()->set('field_reference_3', [5]); or $node->field_reference_3 = ['target_id' => 5];
  6. An exception is thrown and we can see that the field definition doesn't exist on the node, but does exist on field manager.

This might be why #2814963: Support Drupal 7 entity reference fields β†’ is still open/postponed even though plugins exist for it?

Proposed resolution

Reset the entity cache of the entity type that a field instance is attached to after the field instance is migrated.

Remaining tasks

1. Review proposed resolution
2. Reword test comments to accurately describe the issue and problem

User interface changes

Unknown

API changes

Unknown

Data model changes

Unknown

πŸ› Bug report
Status

Needs work

Version

10.1 ✨

Component
MigrationΒ  β†’

Last updated 3 days ago

Created by

πŸ‡ΊπŸ‡ΈUnited States mradcliffe USA

Live updates comments and jobs are added and updated live.
  • Performance

    It affects performance. It is often combined with the Needs profiling tag.

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.

Production build 0.71.5 2024