Currently the migration process plugin accepts any string or array of strings for it's migration value.
This doesn't cause an error, just makes it hard to debug why your migration isn't working integrating if you mis-spell the migration (or have the migrations in the wrong order etc).

So I'm not sure really if this is a bug per se.

CommentFileSizeAuthor
#44 2865247-44.patch14.54 KBmaxocub
#44 interdiff-2865247-42-44.txt3.17 KBmaxocub
#42 2865247-42.patch14.83 KBmaxocub
#42 2865247-42-test-only.patch10.23 KBmaxocub
#42 interdiff-2865247-39-42.txt13.63 KBmaxocub
#39 2865247-39.patch13.63 KBmaxocub
#39 2865247-39-test-only.patch7.87 KBmaxocub
#39 interdiff-2865247-25-39.txt9.32 KBmaxocub
#25 2865247-25.patch4.32 KBjofitz
#25 interdiff-23-25.txt981 bytesjofitz
#23 2865247-23.patch4.01 KBjofitz
#23 interdiff-18-23.txt2.3 KBjofitz
#21 2865247-21.patch4.52 KBjofitz
#21 interdiff-18-21.txt3.69 KBjofitz
#18 2865247-18.patch3.99 KBjofitz
#18 interdiff-15-18.txt3.63 KBjofitz
#15 2865247-15-complete.patch3.18 KBjofitz
#15 2865247-15-test_only.patch1.6 KBjofitz
#15 interdiff-13-15.txt2.89 KBjofitz
#13 2865247-13.patch1.59 KBrakesh.gectcr
#5 2865247-migration-process-plugin-5.patch1.51 KBNickDickinsonWilde
#2 2865247-migration-process-plugin-2.patch1.22 KBNickDickinsonWilde
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

NickWilde created an issue. See original summary.

NickDickinsonWilde’s picture

Here's a very simple patch to check. It won't catch all cases - it is simplistic - but should catch most normal use cases. Could use count($migrations) != count($migration_ids) instead I suppose.

Also moved the existing inline @var comment to the right spot; not exactly in scope but pretty much within the touched code.

NickDickinsonWilde’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 2: 2865247-migration-process-plugin-2.patch, failed testing.

NickDickinsonWilde’s picture

Status: Needs work » Needs review
FileSize
1.51 KB

gerumble... pins reminder to self to make sure to include the use statement(s) on all patches.

Status: Needs review » Needs work

The last submitted patch, 5: 2865247-migration-process-plugin-5.patch, failed testing.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

anpolimus’s picture

Issue tags: +CSKyiv18

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

heddn’s picture

Issue tags: +Needs tests, +Novice

Let's add a test for this. Adding a phpunit test for this seems really fairly trivial, so tagging.

heddn’s picture

Title: Migration process plugin doesn't check validity of provided migration(s) » Migration lookup process plugin doesn't check validity of provided migration(s)
rakesh.gectcr’s picture

Issue tags: -Novice +Novice.

We need to do a reroll for this

rakesh.gectcr’s picture

Status: Needs work » Needs review
FileSize
1.59 KB

rerolled with 8.6.x

Is it the righ direction?

heddn’s picture

Status: Needs review » Needs work

Still needs tests.

  1. +++ b/core/modules/migrate/src/Plugin/migrate/process/MigrationLookup.php
    @@ -155,10 +156,17 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
    +  ¶
    ...
    +  ¶
    

    Nit: whitespace.

  2. +++ b/core/modules/migrate/src/Plugin/migrate/process/MigrationLookup.php
    @@ -155,10 +156,17 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
    +      throw new MigrateException('Some migrations were not matched. Ensure they are migrated first and/or check their spelling. ' . implode(', ', $migration_ids));
    

    sprintf('The (%s) plugin failed because no migrations from (%s) were available.', $this->getPluginId(), implode(', ', $migration_ids))

jofitz’s picture

Version: 8.5.x-dev » 8.6.x-dev
Status: Needs work » Needs review
Issue tags: -Needs tests, -Novice.
FileSize
2.89 KB
1.6 KB
3.18 KB

Addressed corrections and added tests.

The last submitted patch, 15: 2865247-15-test_only.patch, failed testing. View results

heddn’s picture

Status: Needs review » Needs work
+++ b/core/modules/migrate/src/Plugin/migrate/process/MigrationLookup.php
@@ -155,10 +156,17 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
+      throw new MigrateException(sprintf('The (%s) plugin failed because no migrations from (%s) were available.', $this->getPluginId(), implode(', ', $migration_ids)));

The wording looks funny now that I see it concretely. The following seems to work better in my book:

The (migration_lookup) plugin failed because no valid migrations were found. Invalid migrations include: (invalid_migration).

The (migration_lookup) plugin failed because no valid migrations were found. Invalid migrations include: (d7nodepage, d7nodeblog).

jofitz’s picture

Status: Needs work » Needs review
FileSize
3.63 KB
3.99 KB

Re-worded the exception as suggested.
Added a couple more test scenarios.

heddn’s picture

Status: Needs review » Reviewed & tested by the community

Looking good.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/modules/migrate/src/Plugin/migrate/process/MigrationLookup.php
    @@ -155,10 +156,17 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
    +    if (!$migrations) {
    

    if (empty($migrations)) { but also maybe this is not the right condition.

  2. +++ b/core/modules/migrate/src/Plugin/migrate/process/MigrationLookup.php
    @@ -155,10 +156,17 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
    +      throw new MigrateException(sprintf('The (%s) plugin failed because no valid migrations were found. Invalid migrations include: (%s).', $this->getPluginId(), implode(', ', $migration_ids)));
    

    Like the helpful exception but the wording is odd and the use of brackets. How about:
    The '%s' plugin failed because no migrations with the following ID(s) exist: %s.
    Also do we always expect all the $migration_ids to load.
    Ie. should we be testing count($migration_ids) === count($migrations)?

    Or maybe...

    $missing_migrations = array_diff($migration_ids, array_keys($migrations));
    if (!empty($missing_migrations)) {
    
jofitz’s picture

Status: Needs work » Needs review
FileSize
3.69 KB
4.52 KB
  1. Changed condition.
  2. Reworded the exception.

Also added another test for when some, but not all migrations are valid.

alexpott’s picture

Status: Needs review » Needs work
+++ b/core/modules/migrate/src/Plugin/migrate/process/MigrationLookup.php
@@ -162,10 +162,12 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
+    if (!empty($missing_migrations)) {
+      throw new MigrateException(sprintf("The '%s' plugin failed because at least one of the migrations with the following ID(s) does not exist: %s.", $this->getPluginId(), implode(', ', $migration_ids)));

We now know the missing migration(s) - I think we should take the opportunity to use that info in the error since it's helpful.

jofitz’s picture

Status: Needs work » Needs review
FileSize
2.3 KB
4.01 KB

@alexpott It seems the assumption that count($migration_ids) === count($migrations) is not correct - it does not take into account derivatives (I'm not sure whether that's the technical term), i.e. d7_node returns d7_node:article, d7_node:blog, etc.

I can see no better solution than empty($migrations) (without adding a lot of complexity).

I've gone back to the patch in #18 and worked off that, ignoring #21.

maxocub’s picture

Status: Needs review » Needs work
+++ b/core/modules/migrate/tests/src/Unit/process/MigrationLookupTest.php
@@ -298,4 +299,42 @@ public function testMultipleSourceIds() {
+  /**
+   * @covers ::transform
+   *
+   * @dataProvider transformWithInvalidMigrationsDataProvider
+   */
+  public function testTransformWithInvalidMigrations($migration_ids, $invalid_migrations) {

It would be nice to expand this docblock with a one line summary and details about the function's parameters.

jofitz’s picture

Status: Needs work » Needs review
FileSize
981 bytes
4.32 KB

Expanded the docblock.

Status: Needs review » Needs work

The last submitted patch, 25: 2865247-25.patch, failed testing. View results

maxocub’s picture

Status: Needs work » Reviewed & tested by the community

@Jo Fitzgerald: Thanks!

  • alexpott committed b208b07 on 8.6.x
    Issue #2865247 by Jo Fitzgerald, NickWilde, rakesh.gectcr, heddn,...

  • alexpott committed 3c81214 on 8.5.x
    Issue #2865247 by Jo Fitzgerald, NickWilde, rakesh.gectcr, heddn,...
alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed b208b07712 to 8.6.x and 3c812149b7 to 8.5.x. Thanks!

quietone’s picture

Status: Fixed » Needs work

This change breaks the d6_url_alias and d7_url_alias mgrations when content_translation is not enabled. I found this because it broke HEAD on commerce_migrate.

Here is the relevant snippet form d6_url_alias.yml

  node_translation:
    -
      plugin: explode
      source: src
      delimiter: /
    -
      # If the source path has no slashes return a dummy default value.
      plugin: extract
      default: 'INVALID_NID'
      index:
        - 1
    -
      plugin: migration_lookup
      migration: d6_node_translation

So, when d6_url_alias or d7_url_alias (they have the same process in the pipeline) runs and d6_node_translation (or d7_node_translation) isn't found an exception is thrown and the row is not saved. But it should be saved. Before this change migration_lookup would return NULL and the row would save resulting in a successful migration. As it is now, content_translation must be enabled for the URL alias migrations to be successful.

If there is agreement on that can this be reverted?

quietone’s picture

Priority: Normal » Major

Changing priority since this breaks migrations without content_translation enabled. Tempted to mark critical because of the data loss in the migration process.

benjy’s picture

Why does the path migration depend on a content translation migration? That seems wrong, just shown by the fact MigrationLookup now throws an error. Shouldn't node or content_translation edit the migration dynamically to add the "node_translation" parts to the url alias migrations?

  • alexpott committed 26e5826 on 8.6.x
    Revert "Issue #2865247 by Jo Fitzgerald, NickWilde, rakesh.gectcr, heddn...

  • alexpott committed cb990ce on 8.5.x
    Revert "Issue #2865247 by Jo Fitzgerald, NickWilde, rakesh.gectcr, heddn...
alexpott’s picture

Priority: Major » Normal

So neat we discovered two things here. We seem not to have a test for the url alias migrtations without content_translation in core and that there seems to be a valid case when you have no valid migrations to look up.

I've reverted the issue so we can address these things.

quietone’s picture

@alexpott, thanks.

It look like the addition of d6_node_translation to the migration was added in #2827644: Fix path alias migration of translated nodes [D6].

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

maxocub’s picture

I implemented @benji's suggestion from #33 and I moved all translation related code over to Content Translation.

I also modified the URL alias tests so that the first test is run without Content Translation enabled. I included a fail patch to show the bug.

Now, having all the files ready to upload, I'm wondering if I should have done this in a different issue. I'll upload them anyway so we can see if the test are green. If anyone think it should be done in a new issue, I'll be happy to do so.

The last submitted patch, 39: 2865247-39-test-only.patch, failed testing. View results

heddn’s picture

Status: Needs review » Needs work
  1. +++ b/core/modules/content_translation/content_translation.module
    @@ -627,3 +627,49 @@ function content_translation_page_attachments(&$page) {
    +  if (isset($definitions['d7_url_alias'])) {
    +    $definitions['d7_url_alias']['process']['node_translation'] = [
    ...
    +  if (isset($definitions['d6_url_alias'])) {
    +    $definitions['d6_url_alias']['process']['node_translation'] = [
    

    We cannot be sure we know the ID and it won't change. We'll need to use the source plugin's class to check this. Can we add this in a deriver? I would much rather see this there than in a plugin alter. Much cleaner code.

  2. +++ b/core/modules/migrate/src/Plugin/migrate/process/MigrationLookup.php
    @@ -155,10 +156,17 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
    +    // If no migrations are loaded it means either the migration is unavailable
    +    // (perhaps in a disabled module) or doesn't exist (probably mis-typed).
    +    if (empty($migrations)) {
    

    Can we provide a config option to migration_lookup that will let us disable the exception throwing? Defaults to throw.

maxocub’s picture

Thanks for the review @heddn!

  1. I added the UrlAliasDeriver. I hesitated between adding two derivers, one for D6 and one for D7, or only one deriver with an if statement. I chose the later.
  2. I added the validate_migration configuration to the migration_lookup plugin, defaulting to TRUE.
heddn’s picture

Status: Needs review » Needs work
  1. +++ b/core/modules/migrate/src/Plugin/migrate/process/MigrationLookup.php
    @@ -93,6 +96,17 @@
    + * it's unavailable or it doesn't exists, set the 'validate_migration' to FALSE.
    

    For readability, let's state this as, "set validate_migration to FALSE."

  2. +++ b/core/modules/path/src/Plugin/migrate/UrlAliasDeriver.php
    @@ -0,0 +1,94 @@
    +            'plugin' => 'migration_lookup',
    +            'migration' => 'd6_node_translation',
    ...
    +            'plugin' => 'migration_lookup',
    +            'migration' => 'd7_node_translation',
    

    I think this is the only thing different, so can we move that part into the version conditional logic and move the rest outside so as to reduce duplicate code?

I'm also a little torn about defaulting to always throwing an exception. I understand it will help, but it could easily be a distraction. And in a way, if we want to stretch things a little, we are breaking BC. Because previously migrations that were built wouldn't throw that exception. What if we add validate_migration => TRUE to all migration_lookups in core yamls. Then all new migrations will get this feature. But ones that have been running for quite some time will not suddenly start failing. We still want to default to TRUE on any new generated migrations, but not on things have already been generated and someone is currently using.

maxocub’s picture

Status: Needs work » Needs review
FileSize
3.17 KB
14.54 KB
  1. Done.
  2. Done.

I agree that this kinda break BC because an Exception might be thrown where it wasn't before. But I don't understand how we can default to TRUE for new migrations but not for existing (contrib or custom) migrations.

heddn’s picture

We can sorta do that for new if we assume that folks are copy/pasting the yaml files or using some type of config system with migrate_plus config entities. In those cases, the yml files they use are copies. If we just change all of core's templates and all uses of derivers, etc, to set validate_migration = TRUE, then we sorta get this for new migrations and not for existing. If we assume that existing copies wouldn't have the validate_migration in their yaml files because they copied them before we added it everywhere.

maxocub’s picture

Status: Needs review » Needs work

Discussed in the Migrate maintainer meeting. First, we should move the url_alias stuff to a new issue. Second, let's add this functionality with a default to FALSE, so we don't break BC, and open a follow-up to figure out how to implement it (adding the config to all migration_lookup plugins?).

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Version: 9.4.x-dev » 8.5.x-dev
Status: Needs work » Fixed

This was committed to Drupal 8.5.x and re-opened because it the url_alias migrations were failing if content_translation was not enabled. That was a problem with a change of behavior introduced here and was fixed in #3086952: Migration Lookup should catch PluginNotFoundException exceptions and ignore them. and a test without content_translation was added. The following work here was fixing the problem by adding a lot more code by using a deriver.

Therefor, restoring the issue meta data to the time this was committed.

Thanks.

Status: Fixed » Closed (fixed)

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