Subprocess plugin fails silently if incoming value is not an array - throws exception in wrong place?

Created on 10 November 2023, 7 months ago

Problem/Motivation

1. If the subprocess plugin receives a non-array as its incoming value, it returns an empty array and doesn't complain.
2. However, if it gets an array of scalars, then it does throw an exception.

For point, I think an exception should be thrown, because if the developer is trying to run a subprocess on a scalar value, then either they have messed up their migration definition, or their data is bad.

For point 2, I'm not sure this exception is correct. Suppose my source data looks like this:

        'property' => [
          'subfield' => 42,
        ],

and my migration pipeline has this:

process:
  property:
    plugin: subprocess
    process:
      subfield: subfield

Then I want subfield to get the value of 42 and that looks ok to me? But currently that source data causes an exception.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

πŸ› Bug report
Status

Active

Version

11.0 πŸ”₯

Component
MigrationΒ  β†’

Last updated about 17 hours ago

Created by

πŸ‡¬πŸ‡§United Kingdom joachim

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @joachim
  • πŸ‡ΊπŸ‡ΈUnited States mikelutz Michigan, USA

    Yes, we should probably throw an exception in the first case. The reason we don't is because of stubbing, when we run migrations with null source values, we don't want the subprocess to explode when it gets null instead of an empty array. We could make this more explicit, though, return an empty array on null only, and document it all better.

    The second case doesn't make any sense to use subprocess on. Sounds like you want to treat an array of scalars as if it's a single subrow to process, but that's not what subprocess does, and you wouldn't need subprocess, you could just set property/0/subfield:property/subfield directly.

Production build 0.69.0 2024