Process plugin entity_generate failing to set lookup

Created on 18 November 2022, over 2 years ago

Problem/Motivation

I am seeing a regression where a migration using the entity_generate is properly setting the entity reference when the entity is generated but when it finds an existing, the entity reference is not set even though I have verified it was found.
Subsequent runs of a migration actually unset the reference if the field is set to an overwrite.

I stepped through it and have connected it to this bit of code
https://git.drupalcode.org/project/migrate_plus/-/blob/6.0.x/src/Plugin/...

if (!($result = parent::transform($value, $migrate_executable, $row, $destination_property))) {
      $result = $this->generateEntity($value);
    }

parent::transform() if it finds the existing term, returns
["1051"]
which does not result in the entity reference being set.
But
this->generateEntity()
returns
"1051"
Which does result in the entity being set.

Steps to reproduce

field_administration:
    -
      plugin: entity_generate
      source: office_name
      entity_type: taxonomy_term
      ignore_case: true
      value_key: name
      bundle_key: vid
      bundle: administration
      values:
        name: office_name
        parent: '@pseudo_field_district_tid'
        field_product: 'constants/product_term_tid'

This failure to set the entity is likely related to the entity reference field supporting multiples or not. If it does not, it can not handle an array of entity ids.

The problem is, that since sometimes the process plugin returns an array, and sometimes it returns a value, I can not solve this by just adding another process plugin like array_shift to get a single value because that plugin throws an exception if you pass it a value instead of an array.

I thought maybe I could leverage this single_value but that doesn't seem to do anything but pass the value directly through and the documentation for it is wrong https://git.drupalcode.org/project/migrate_plus/-/blob/6.0.x/src/Plugin/...

My temporary solution is to create a callable that optionally returns the first item from the array or pases the value thorugh if not an array.

Proposed resolution

My proposed resolution is to have generateEntity() return an array containing the entity id, so that it will be consistent with the array pattern that comes from the parent::transform()

This however would be a breaking change, but as far as I can tell, its already broken.

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Active

Version

6.0

Component

Plugins

Created by

πŸ‡ΊπŸ‡ΈUnited States swirt Florida

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.

Production build 0.71.5 2024