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.

Command icon 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

fchometon created an issue. See original summary.

heddn’s picture

Version: 6.1.3 » 6.1.x-dev
Status: Active » Needs work
Issue tags: +Needs tests

Can we add some test coverage for this so we don't accidentally break this again?

fchometon’s picture

I’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.

fchometon’s picture

I 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.

fchometon’s picture

I’ve made the necessary corrections to the migration IDs in the tests. Everything is now fixed, and the ordering checks are working correctly.

cboyden’s picture

Status: Needs work » Needs review

Setting to needs review because tests have been updated.

heddn’s picture

Status: Needs review » Fixed
Issue tags: -Needs tests

Thanks for the fixes here.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • heddn committed 95f72bf4 on 6.1.x authored by fchometon
    fix: #3572002 migration_dependencies.optional ignored since 6.1.3
    
    By:...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

ressa’s picture

I 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 --all now 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?

heddn’s picture

Release tagged

ressa’s picture

Fantastic, thank you @heddn.