The migrate list command calls $manager->createInstances() with an empty array, which instantiates all the migration plugins.
It would be better to filter on migration IDs, groups, and tags based on the plugin definitions, and then only instantiate the plugins actually needed.
Firstly, it would improve performance, and second, instantiating migrations causes their requirements to be checked, which might not be desirable. (Though a bug in core means that some migrations check requirements even without being instantiated: #3187480: D6NodeDeriver calls checkRequirements() when building migration plugin definitions.)
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | migrate_tools.2969227.backport-8.5.0.patch | 4.46 KB | joachim |
Issue fork migrate_tools-2969227
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
joachim commentedMR: https://git.drupalcode.org/project/migrate_tools/-/merge_requests/2
This rearranges the filtering on migration IDs, groups, and tags, so all that is done with the plugin definitions. Plugins are only instantiated once the list of plugins IDs has been filtered.
Comment #4
joachim commentedComment #5
joachim commentedHere's a backport of the MR for 8.x-5.0.
Comment #7
heddnThe failing test is a legit failure. We should the tests expectations for migrate status with an invalid migration.
Comment #8
joachim commentedComment #9
heddnTests are still not passing.
Comment #10
joachim commentedFound the problem. The kernel test is doing
> $this->commands->status('invalid_plugin');
which is calling the status() method on MigrateToolsCommands directly. I had assumed this call was doing some sort of magic to simulate a Drush call, but it's just:
The problem is this:
The default values self::REQ are there to tell Drush's command registration system that the group option is required. (Though I don't understand that part -- the --group option is NOT required!)
The command processing in Drush/Symfony presumably pass the $options array so that the default value of the $options parameter is never actually seen by the status() method.
Except in the kernel test, which bypasses all that.
The best fix would be to properly simulate Drush commands, which is out of scope here.
Quick fix would be to pass in an empty array as the $options parameter.
What do you think?
Comment #11
heddnQuick fix seems fine to me.
Comment #12
joachim commentedComment #13
heddnI think we have to pass in actual default values as well.
Comment #14
joachim commentedComment #15
joachim commentedRebased the MR on the 6.0.x branch.
Comment #16
joachim commentedRebased.
Comment #17
joachim commentedDrupal\Tests\migrate_tools\Kernel\MigrateImportTest::testImport passed for me locally.
Comment #18
ronchica commentedFWIW, I needed this patch in order to be able to import or check the status of a migration group.
Due to a dependency, I needed to enable the Migrate Drupal module, which appears to add some migrate plugins to the available list of plugins. I kept getting a '/SQLSTATE[HY000] [2002] Connection refused' error when trying to run the migration group (a single migration ran fine).
After a bunch of time thinking the issue was with my DDEV setup, I debugged using xdebug, found all those plugins trying to connect to a non-existent db, which led me to this issue. Applying the patch enables the status and import commands to work on a migration group, and the import looks good. I still get the connection error once in a while though, so there might be something else that needs to be fixed in my case.
Comment #19
heddnThere's still test failures on the MR.
Comment #21
heddnComment #24
unstatu commentedHello everyone :)
I think that this patch had a side effect. I'm not sure if it was desired or not.
Since 6.1.3, the migrations listed with the migrate:status drush command are not sorted in the same order as they are run. That is, taking into account their dependencies.
Comment #25
fchometonI’m seeing the same behavior.
Since 6.1.3, migrations are no longer sorted according to their dependencies.
This comes from migrationsList(), which no longer uses $manager->createInstances([]) and therefore never calls buildDependencyMigration().
As a result, dependency-based ordering (including migration_dependencies.optional) is lost.
I have prepared a patch that restores dependency-based ordering for filtered migrations by calling buildDependencyMigration() on the already instantiated migrations after requirements checks :
https://www.drupal.org/project/migrate_tools/issues/3572002