MigrationLookup doesn't create stub when there's multiple migrations.

Created on 30 June 2017, over 7 years ago
Updated 11 April 2023, over 1 year ago

When you have multiple source migrations like this:

process:
  uid:
    plugin: migration_lookup
    migration: 
      - users
      - members
    source: author

the documentation β†’ says that

If the migration does not find the source ID in the migration map it will create a stub entity for the relationship to use. This stub is generated by the migration provided. In the case of multiple migrations the first value of migration list will be used, but you can select the migration you wish to use to create the stub

Even the code seems to suggest that that is the intention:

    if (!$destination_ids && ($self || isset($this->configuration['stub_id']) || count($migrations) == 1)) {
      // If the lookup didn't succeed, figure out which migration will do the
      // stubbing.
      if ($self) {
        $migration = $this->migration;
      }
      elseif (isset($this->configuration['stub_id'])) {
        $migration = $migrations[$this->configuration['stub_id']];
      }
      else {
        $migration = reset($migrations);
      }

But that last else can never be reached.
$destination_ids is empty so that part of the condition is satisfied.
count($migrations) equals 2 so the last part of the condition is ignored.
This means that either $self is true or $this->configuration['stub_id'] is set.
In the first case the top branch of the if/elseif/else is executed
In the second case the middle branch is executed.
The third can never be executed.

Workaround: specify a stub_id in your migration.

πŸ› Bug report
Status

Needs work

Version

10.1 ✨

Component
MigrationΒ  β†’

Last updated 3 days ago

Created by

πŸ‡³πŸ‡±Netherlands JvE

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

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.

  • First commit to issue fork.
Production build 0.71.5 2024