From 0e13819245bba727b151968e64e6ea642b7a539c Mon Sep 17 00:00:00 2001
From: Alex Pott <alex.a.pott@googlemail.com>
Date: Sat, 27 Feb 2021 10:53:59 +0000
Subject: [PATCH] Issue #3097312 by quietone, Wim Leers, raman.b, benjifisher:
 Never generate migration dependencies on derivatives of itself is a
 self_referencing migration_lookup

---
 core/modules/migrate/src/Plugin/Migration.php            | 9 +++++++++
 .../migrate/tests/src/Kernel/Plugin/MigrationTest.php    | 6 ++++++
 2 files changed, 15 insertions(+)

diff --git a/core/modules/migrate/src/Plugin/Migration.php b/core/modules/migrate/src/Plugin/Migration.php
index 406e30b4bdac..c4ba20281150 100644
--- a/core/modules/migrate/src/Plugin/Migration.php
+++ b/core/modules/migrate/src/Plugin/Migration.php
@@ -628,6 +628,15 @@ protected function findMigrationDependencies($process) {
     $return = [];
     foreach ($this->getProcessNormalized($process) as $process_pipeline) {
       foreach ($process_pipeline as $plugin_configuration) {
+        // If the migration uses a deriver and has a migration_lookup with
+        // itself as the source migration, then skip adding dependencies.
+        // Otherwise the migration will depend on all the variations of itself.
+        // See d7_taxonomy_term for an example.
+        if (isset($this->deriver)
+            && $plugin_configuration['plugin'] === 'migration_lookup'
+            && $plugin_configuration['migration'] == $this->getBaseId()) {
+          continue;
+        }
         if (in_array($plugin_configuration['plugin'], ['migration', 'migration_lookup'], TRUE)) {
           $return = array_merge($return, (array) $plugin_configuration['migration']);
         }
diff --git a/core/modules/migrate/tests/src/Kernel/Plugin/MigrationTest.php b/core/modules/migrate/tests/src/Kernel/Plugin/MigrationTest.php
index c58df28af55f..706318e83534 100644
--- a/core/modules/migrate/tests/src/Kernel/Plugin/MigrationTest.php
+++ b/core/modules/migrate/tests/src/Kernel/Plugin/MigrationTest.php
@@ -108,6 +108,8 @@ public function getProcessPluginsExceptionMessageProvider() {
   public function testGetMigrationDependencies() {
     $plugin_manager = \Drupal::service('plugin.manager.migration');
     $plugin_definition = [
+      'id' => 'foo',
+      'deriver' => 'fooDeriver',
       'process' => [
         'f1' => 'bar',
         'f2' => [
@@ -145,6 +147,10 @@ public function testGetMigrationDependencies() {
             ],
           ],
         ],
+        'f7' => [
+          'plugin' => 'migration_lookup',
+          'migration' => 'foo',
+        ],
       ],
     ];
     $migration = $plugin_manager->createStubMigration($plugin_definition);
-- 
GitLab