1

I'm trying to skip fields that are not present in my source file or that are empty, but I keep getting "Migration failed with source plugin exception: Passed variable is not an array or object"

This is what I've tried in YML:

field_contact:
    -
      plugin: skip_on_empty
      method: process
      source: contact_array
    -
      plugin: sub_process
      source: contact_array
      process:
        target_id:
          plugin: migration_lookup
          migration: import_contact_json
          source: Name

and

field_point_of_contact:
    plugin: sub_process
    source: contact_array
    process:
      target_id:
        -  
          plugin: skip_on_empty
          method: process
          source: name
        -
          plugin: migration_lookup
          migration: registry_import_pocs_json
          source: Name

Both of them have the same output (i.e. the error described above).

Can someone point me in the right direction, please?

  • the code for "skip_on_empty" process plugin is a bit strange. The condition is: if (!$value). I would expect to use isset() or empty() – Stefan Feb 17 at 17:16
  • skip_on_empty does a PHP boolean evalutation. The name might be misleading from a PHP programmers point of view, but it is a quite sensible default in the context of migration sources (empty source string, different boolean representations,..) – Hudri Feb 20 at 8:51
  • 1
    I don't think skip_on_empty is your problem here. Try to debug your source fields with process_dummy_field: | plugin: callback | callable: var_dump | source: my_source_field (replace pipe with intented newline) – Hudri Feb 20 at 9:01
  • 1
    In some point your contact_array is not an array and as @Hudri said skip_on_empty will not prevent you from source passing down the wrong value to subprocess. – d70rr3s Feb 20 at 9:46
  • 1
    Another hint when you use multiple process plugins the source is passed down from each process to the next one, so you don't need to issue source: my_source_field each time, only for the first process in the chain. Also I see that you have a typo in your code can you confirm your source is Name or name? – d70rr3s Feb 20 at 12:29
0

It is difficult to help without seeing the structure of your source file (at least 1 sample record). But, here are some pointers:

  • At first glance, the error message says something about a source plugin exception. I believe the error might be stemming from the source plugin configuration.
  • The approach you are taking with skip on empty seems to be in the correct direction.
  • Depending on the data that the field contains, you might have to handle it differently. I usually add the following to debug exactly what is being received by a particular field process. Also, make sure that the value being sent to the migrate_lookup plugin is an array.
# ...
process:
  field_point_of_contact:
    - plugin: callback
      callable: print_r
      source: name
# ...
  • Have you tried removing the skip on empty part? I don't remember correctly, but migrate lookup might be skipping empty values by itself.
  • An array with empty strings is not considered empty. If your source provides values like [''], you might have to send the array through an array_filter() to remove empties.

I hope this helps. If it doesn't, you might want to share one row of fake data.

|improve this answer|||||
0

I've promised I'll come back when this is solved, but it took a while :) Thank you everyone for helping out. It turned out the issue was the fact that "migration_dependencies" was set to "required", so any missing data in the source file was firing that exception. After hours of pulling my hair out, the fix was to change migration_dependencies to "optional" And no skip_on_empty is needed in this case.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.