Better document how skip_on_empty works with multiple value sources

Created on 31 August 2017, almost 7 years ago
Updated 13 June 2023, 12 months ago

Issue Summary

skip_on_empty's interaction with array sources that are considered 'multiple' values is poorly documented, and can be unintuitive.

Proposed resolution

Add documentation to the top of the plugin, that explicitly describes the expected behavior of skip_on_empty when dealing with multiple value sources, including when the source array contains 0 elements.

Original issue summary

I have been scratching my head over this issue. The source sometimes has a blank offers, sometimes it is an array with data and sometimes it is an empty array - like this one:
https://api.hel.fi/linkedevents/v1/event/matko:16134/

With the latter example I was getting a bunch of Array index missing, extraction failed exceptions from the extract plugin, despite the skip_on_empty plugin running before, as you can see from my yml file:

  field_offers_is_free:
    -
      plugin: skip_on_empty
      method: process
      source: offers
    -
      plugin: extract
      index:
        - 0
        - is_free
  field_offers_info_url:
    -
      plugin: skip_on_empty
      method: process
      source: offers
    -
      plugin: extract
      default: false
      index:
        - 0
        - info_url
        - fi

I managed - in the end - to track down the reason for why our skip_on_empty plugin was never called: When Get sets $multiple to true, processRow in MigrateExecutable runs a foreach on the value - causing the whole skip_on_empty plugin to be skipped.

With this quick fix in modules/migrate/src/Plugin/migrate/process/Get.php's transform function things work fine for me:

    if (is_string($source)) {
      $a = is_array($return[0]);
      $b = !empty($return[0]);
      $this->multiple = $a && $b;
      return $return[0];
    }

Did I encounter a bug in Migrate or should I change my migration configuration?

📌 Task
Status

Closed: won't fix

Version

9.5

Component
Migration  →

Last updated about 2 hours ago

Created by

🇫🇮Finland badrange

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

    Primarily changes documentation, not code. For Drupal core issues, select the Documentation component instead of using this tag. In general, component selection is preferred over tag selection.

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 States texas-bronius

    I think @vinodhinisureshbabu in #37 poses a nice solution:
    ```
    field_plaintext_author:
    - plugin: parse_lcm_author
    source: body/0/value
    - plugin: default_value
    default_value: 0
    - plugin: skip_on_value
    value: 0
    method: row
    ```
    My plugin `parse_lcm_author` returns an array of values (or empty array `[]`), and `default_value` understands an empty array to require a default value. I used 0 but any scalar value will do. (skip row or process as is appropriate to your needs -- I'm building paragraphs in this migration, so it was good to get out without a mapping made)

Production build 0.69.0 2024