Problem/Motivation
Since migrate_tools 6.1.3, migrations are no longer executed in the correct dependency order.
Specifically, the `migration_dependencies.optional` key is ignored, and `migrate:status` does not display migrations in the order they will actually run.
This is a side effect of the change introduced in #2969227, which aimed to improve performance by filtering migrations before instantiation.
Steps to reproduce
1. Define a migration with `migration_dependencies.optional` pointing to another migration.
2. Run `drush migrate:status` or `drush migrate:import `.
3. Observe that the optional dependency is not executed before the dependent migration.
4. Compare with the same setup on migrate_tools 6.1.2 – the order and optional dependency are respected.
Proposed resolution
Restore dependency-based ordering for filtered migrations in `migrationsList()`.
The patch should:
- Use the already-instantiated migrations (after requirements checks)
- Call `buildDependencyMigration()` on this filtered set
- Ensure `required` and `optional` dependencies are respected
- Avoid re-instantiating all migrations to maintain performance.
User interface changes
None. The `migrate:status` output will now correctly reflect dependency order.
API changes
None. Only internal ordering of migrations is affected.
Data model changes
None. The underlying migration definitions and dependencies remain unchanged.
Issue fork migrate_tools-3572002
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
heddnCan we add some test coverage for this so we don't accidentally break this again?
Comment #4
fchometonI’ve added a test to verify that optional migration dependencies are respected.
- Three test migrations were created with a common order_ prefix: order_alpha, order_beta, order_gamma.
- They form a dependency chain: order_alpha → order_beta → order_gamma.
- The test calls migrationsList via the Drush status command (with names-only) and asserts that the returned order respects the dependencies.
Comment #5
fchometonI realized that the migration IDs I used in the tests are incorrect. The tests are therefore not valid, and I need to revise them before they can pass reliably. I’ll update the tests with the correct IDs and ensure the ordering checks work as intended.
Comment #6
fchometonI’ve made the necessary corrections to the migration IDs in the tests. Everything is now fixed, and the ordering checks are working correctly.
Comment #7
cboyden commentedSetting to needs review because tests have been updated.
Comment #8
heddnThanks for the fixes here.
Comment #12
ressaI was also seeing this while running migrations for WordPress Migrate, see #3578768: drush migrate:import --all fails due to Migrate Tools regression.
I can confirm that using the dev-release fixes it, and a previously failing
drush migrate:import --allnow works again. It used to stall with[error] Migration my_wordpress_comment_post did not meet the requirements. Missing migrations my_wordpress_content_post.Since this can cause migrations to mysteriously fail, and requirements are widely used, perhaps a fresh release could be considered?
Comment #13
heddnRelease tagged
Comment #14
ressaFantastic, thank you @heddn.