Problem/Motivation

CR Entity type and bundle machine names have a maximum length of 32 characters

Running a migration from a Drupal 7 test site where I have migrate_example enabled, I got a bunch of errors from d7_comment_type like:

Attempt to create a bundle with an ID longer than 32 characters: comment_node_migrate_example_beer().
(/Users/mryan/Sites/d8/core/lib/Drupal/Core/Entity/Entity.php:384)

In the D7 field_config_instance table, for example, the bundle corresponding to field_name comment_body and entity_type comment may be comment_node_migrate_example_beer - more than the 32 character limit for bundle names in D8. We might simply truncate them at 32 (comment_node_migrate_example_bee in this example), and that will work for these particular bundles, but there may be other cases out there with similar common prefixing that won't uniquely truncate at 32, so we might want to add some intelligence to it...

Proposed resolution

Use the make_unique_entity_field process plugin for the d6 and d7 comment type migrations. The d7_field_instance migration uses a new process plugin. field_bundle, to determine the bundle name and the d7_field_formatter_settings and d7_field_instance_widget_settings are altered to get the bundle on a migration_lookup for d7_field_instance.

Remaining tasks

  • Reroll (Novice)
CommentFileSizeAuthor
#108 2565931-108.patch30.32 KBquietone
#108 interdiff-106-108.txt592 bytesquietone
#106 2565931-106.patch29.57 KBquietone
#106 interdiff-103-106.txt995 bytesquietone
#105 2565931-105.patch29.63 KBquietone
#105 interdiff-103.105.txt1.25 KBquietone
#103 reroll_diff_88-103.txt6.74 KBsokru
#103 2565931-103.patch29.56 KBsokru
#98 2565931-98.patch29.68 KBanushrikumari
#94 2565931-88.patch30.3 KBquietone
#90 diff-84-88.txt342 bytesquietone
#88 2565931-88.patch30.3 KBKapilV
#84 2565931-84.patch30.3 KBquietone
#84 interdiff-79-84.txt1.85 KBquietone
#79 2565931-79.patch30.24 KBquietone
#79 interdiff-78-79.txt1.58 KBquietone
#78 2565931-78.patch29.12 KBquietone
#78 diff-71-78.txt4.47 KBquietone
#71 2565931-71.patch29.18 KBquietone
#71 interidf-69-71.txt1.37 KBquietone
#69 2565931-69.patch29.05 KBquietone
#69 interdiff-67-69.txt3.07 KBquietone
#67 2565931-67.patch27.42 KBquietone
#67 diff-65-67.txt5.47 KBquietone
#65 2565931-65.patch29.17 KBquietone
#65 interdiff-64-65.txt1.29 KBquietone
#64 2565931-64.patch29.17 KBquietone
#64 interdiff-62-64.txt5.2 KBquietone
#62 interdiff-57-62.txt706 bytesshaktik
#62 2565931-62.patch29.07 KBshaktik
#59 interdiff-55-57.txt1019 bytesshaktik
#57 2565931-57.patch28.84 KBshaktik
#55 2565931-55.patch28.45 KBquietone
#55 interdiff-53-55.txt4.4 KBquietone
#53 2565931-53.patch25.64 KBquietone
#53 interdiff-51-53.txt3.85 KBquietone
#51 2565931-51.patch24.06 KBquietone
#51 interdiff-46-51.txt8.11 KBquietone
#48 2845485-84.patch15.97 KBquietone
#48 interdiff-82-84.txt1.81 KBquietone
#46 2565931-46.patch15.3 KBquietone
#46 interdiff-41-46.txt2.02 KBquietone
#44 2565931-44.patch14.64 KBquietone
#44 interdiff-41-44.txt1.36 KBquietone
#41 2565931-41.patch13.38 KBquietone
#41 interdiff-39.41.txt5.1 KBquietone
#39 2565931-39.patch10.22 KBquietone
#39 interdiff-37-39.txt2.44 KBquietone
#37 2565931-37.patch10.29 KBquietone
#37 interdiff-35-37.txt4.61 KBquietone
#35 2565931-35.patch7.19 KBquietone
#35 interdiff-32-35.txt2.29 KBquietone
#32 2565931-32.patch8.85 KBquietone
#32 interdiff-23-32.txt10.8 KBquietone
#23 2565931-23.patch9.35 KBwturrell
#22 2565931-22.patch10.31 KBclemens.tolboom
#14 2565931-14.patch10.59 KBjofitz
#14 interdiff-12-14.txt6.47 KBjofitz
#12 2565931-12.patch5.14 KBjofitz
#12 interdiff-11-12.txt508 bytesjofitz
#11 2565931-11.patch5.14 KBjofitz
#8 2565931-8.patch5.12 KBjofitz
#8 interdiff-5-8.txt4.19 KBjofitz
#5 handle_long_comment-2565931-5.patch5.05 KBmitrpaka
#2 handle_long_comment-2565931-2.patch5.05 KBmikeryan
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mikeryan created an issue. See original summary.

mikeryan’s picture

Status: Active » Needs work
FileSize
5.05 KB

This is a start - there are a bunch of downstream migrations that need to be modified to reference the proper truncated comment bundle name. Still getting this failure:

Upgrading d7_comment_entity_form_display_subject
array_key_exists(): The first argument should be either a string or an integer NestedArray.php:77 
array_key_exists(): The first argument should be either a string or an integer NestedArray.php:77
array_key_exists(): The first argument should be either a string or an integer NestedArray.php:77
array_key_exists(): The first argument should be either a string or an integer NestedArray.php:77 
array_key_exists(): The first argument should be either a string or an integer NestedArray.php:77

Downstream, I'm also getting these errors, not sure whether they're a consequence of this issue or a separate issue:

Upgrading d7_field_formatter_settings
Missing required properties for an EntityDisplay entity.
(/Users/mryan/Sites/d8/core/lib/Drupal/Core/Entity/EntityDisplayBase.php:127)
The "image__large" plugin does not exist.
(/Users/mryan/Sites/d8/core/lib/Drupal/Component/Plugin/Discovery/DiscoveryTrait.php:57)
The "image_link_content__medium" plugin does not exist.
(/Users/mryan/Sites/d8/core/lib/Drupal/Component/Plugin/Discovery/DiscoveryTrait.php:57)

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.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.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

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

mitrpaka’s picture

Checked if patch needed a re-roll. Offset spotted. Patch file updated.

Hunk #1 succeeded at 26 (offset 2 lines).
patching file core/modules/field/migration_templates/d7_field_instance.yml
Hunk #1 succeeded at 11 (offset 2 lines).

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

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.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 reroll

Now that dedupe has been renamed, this needs a re-roll.

jofitz’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
4.19 KB
5.12 KB

Updated references to plugins "dedupe_entity" ("make_unique_entity_field") and "migration" ("migration_lookup").

Status: Needs review » Needs work

The last submitted patch, 8: 2565931-8.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.

jofitz’s picture

FileSize
5.14 KB

Patch in #8 no longer applies. Re-rolled.

jofitz’s picture

Status: Needs work » Needs review
FileSize
508 bytes
5.14 KB

Correct invalid YAML.

heddn’s picture

Status: Needs review » Needs work
+++ b/core/modules/comment/migration_templates/d6_comment_type.yml
@@ -8,7 +8,15 @@ source:
+        length: 32

+++ b/core/modules/comment/migration_templates/d7_comment_type.yml
@@ -8,7 +8,15 @@ source:
+        length: 32

If we combine the name of 32 characters with 1 or 2 additional numbers to make it unique, then that results in a unique name of 33 or 34 characters. I think we want to drop the length to 30 characters.

jofitz’s picture

Status: Needs work » Needs review
FileSize
6.47 KB
10.59 KB

Reduced the number of characters from 32 to 30, as suggested.
Fixed bugs in a couple of tests.

jofitz’s picture

Status: Needs review » Needs work

Many tests will still fail because the new markup to obtain the bundle:

  bundle:
    -
      plugin: migration_lookup
      migration:
        - d7_node_type
        - d7_comment_type
      source: bundle

...fails if the bundle is "user". I have been unable to come up with a solution. Any suggestions?

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.

NiklasBr’s picture

Issue tags: +migrate-d6-d8

Adding Drupal 6 tag because this happens on 8.5.x when migrating from 6.x as well.

NiklasBr’s picture

We hit this hard 32 character limit on multiple CCK content types when migrating from D6.

When we changed the class constant from 32 to 64 all errors disappeared. Though we likely just silenced some errors.

What I don't understand is the motivation for keeping the limit at around 30 to begin with. Why not allow even 100 characters? Verbosity can be a good thing, right?

quietone’s picture

Issue tags: +migrate-d7-d8

The original report is for D7->D8, so adding that tag.

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

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should 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.

clemens.tolboom’s picture

Issue summary: View changes
Issue tags: +Needs reroll

See to CR Entity type and bundle machine names have a maximum length of 32 characters

I tried to do a reroll from fc4a1d6be073a2542d21a2b8479c76370a6adcf4 but failed.

clemens.tolboom’s picture

I altered path according to #2917883: Rename 'migration_templates' directories in core modules to 'migrations' so files are found at least. Hope that is useful?

I cannot remember we got (D6) ID warning from #2876085: Before upgrading, audit for potential ID conflicts

Regarding core/modules/comment/migrations/d6_comment_type.yml I'm not sure how to apply this to the new settings

Current core

process:
  target_entity_type_id: 'constants/entity_type'
  id:
    -
      plugin: concat
      source:
        - 'constants/id_prefix'
        - type
    -
      plugin: static_map
      bypass: true
      # The Forum module provides its own comment type (comment_forum), which we
      # want to reuse if it exists.
      map:
        comment_node_forum: comment_forum
  label:

and this patch

  process:
    target_entity_type_id: 'constants/entity_type'
+   id:
+       -
+         plugin: get
+         source: comment_type
+       -
+         plugin: make_unique_entity_field
+         entity_type: comment_type
+         field: id
+         length: 30
    label: label
wturrell’s picture

Here's a patch I've rebuilt from scratch, based on #22, against the latest 8.6.x core.
It applies cleanly but doesn't solve the issue (I'm yet to write any migrations of my own so my knowledge is limited).

Maybe someone can take a look at it?

savkaviktor16@gmail.com’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll

The last submitted patch, 22: 2565931-22.patch, failed testing. View results

The last submitted patch, 2: handle_long_comment-2565931-2.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 23: 2565931-23.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

quietone’s picture

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

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.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.

Summit’s picture

Hi,
I also bumped in to this error:

Attempt to create a bundle with an ID longer than 32 characters: comment_node_gallery_image_landen(). (/web/core/lib/Drupal/Core/Entity/EntityBase.php:439 

Is there any news that this can be fixed, or do I need to alter my nodetypes to smaller amount of characters?

greetings, Martijn

steinmb’s picture

I worked around the problem by not migrating the config. Manually created the D8/9 node bundles and only migrated the content.

quietone’s picture

Version: 8.8.x-dev » 9.1.x-dev
Status: Needs work » Needs review
FileSize
10.8 KB
8.85 KB

I should have made a reroll from #23 but I just forgot. IIRC the changes were to the setup methods of the test files because there were cleanup up in the meantime. If someone wants to see it I will make one.

So, just making a start here. This patch , aside from the reroll, adds a node type with a 32 character name to the drupal 7 test fixture. Then the MigrateNodeTypeTest and MigrateCommentTypeTests were updated and that is all.

The other migrations in this patch need to be checked and there is still a D6 version to make. And fail patches.

Status: Needs review » Needs work

The last submitted patch, 32: 2565931-32.patch, failed testing. View results

clemens.tolboom’s picture

Should we really (care about) migrate D6 to D9?

quietone’s picture

Status: Needs work » Needs review
FileSize
2.29 KB
7.19 KB

Removed the changes to d7_field_formatter_settings.yml. I am not sure why that is changing the bundle process to allow for a comment bundle. The field is definitely on a node not a comment. And fixed an error in the fixture.

Status: Needs review » Needs work

The last submitted patch, 35: 2565931-35.patch, failed testing. View results

quietone’s picture

Status: Needs work » Needs review
FileSize
4.61 KB
10.29 KB

This introduces a new process plugin to determine the bundle in d7_field_instance and changes the migration yml accordingly. And also changes d7_field_formatter to do a migration lookup on d7_field_instance to get the bundle whereas before it repeated the process.

There is still work to do here but I'm finished with this for now.

Status: Needs review » Needs work

The last submitted patch, 37: 2565931-37.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

quietone’s picture

Status: Needs work » Needs review
FileSize
2.44 KB
10.22 KB

Didn't appreciate what the static_map was doing with the bundle. So, restore that and alter the new process plugin to use the output of the static_map unless it is a comment bundle, then do a migration lookup to get the correct name.

Status: Needs review » Needs work

The last submitted patch, 39: 2565931-39.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

quietone’s picture

Fixing some more tests and fixing coding standard issues.

quietone’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 41: 2565931-41.patch, failed testing. View results

quietone’s picture

Status: Needs work » Needs review
FileSize
1.36 KB
14.64 KB

Still working on the tests.

Status: Needs review » Needs work

The last submitted patch, 44: 2565931-44.patch, failed testing. View results

quietone’s picture

Status: Needs work » Needs review
FileSize
2.02 KB
15.3 KB

A few more test fixes.

Status: Needs review » Needs work

The last submitted patch, 46: 2565931-46.patch, failed testing. View results

quietone’s picture

Status: Needs work » Needs review
FileSize
1.81 KB
15.97 KB

Add assertions to D7 field tests and add changes to the D6 fixture and d6 tests.

Status: Needs review » Needs work

The last submitted patch, 48: 2845485-84.patch, failed testing. View results

quietone’s picture

Unrelated fail, retesting.

quietone’s picture

Status: Needs work » Needs review
FileSize
8.11 KB
24.06 KB

The patch in #48 is for another issue and I didn't even notice until I came back to self-review.

So, here is the correct patch, which add assertions to D7 field tests and adds a D6 migration.

Status: Needs review » Needs work

The last submitted patch, 51: 2565931-51.patch, failed testing. View results

quietone’s picture

Status: Needs work » Needs review
FileSize
3.85 KB
25.64 KB

Change the name of the new node type in the drupal6 test fixture. Need to install comment into d6/MograteFieldInstanceTest in order to test the long comment name.

Still need to check the other d6 field migrations and test.

Status: Needs review » Needs work

The last submitted patch, 53: 2565931-53.patch, failed testing. View results

quietone’s picture

Status: Needs work » Needs review
FileSize
4.4 KB
28.45 KB

Correct the name of the new node type in the drupal6 fixture, add more d6 tests.

Status: Needs review » Needs work

The last submitted patch, 55: 2565931-55.patch, failed testing. View results

shaktik’s picture

shaktik’s picture

Status: Needs work » Needs review
shaktik’s picture

FileSize
1019 bytes

Added interdiff txt file for #57 to fixing test cases.

Status: Needs review » Needs work

The last submitted patch, 57: 2565931-57.patch, failed testing. View results

shaktik’s picture

Assigned: Unassigned » shaktik

I am working on it.

shaktik’s picture

Status: Needs work » Needs review
FileSize
29.07 KB
706 bytes
shaktik’s picture

Assigned: shaktik » Unassigned

Hi @quietone,

Fixed test case issue, Kindly review.

quietone’s picture

@shaktik, thank you.

Did a bit of cleanup and add comments. The biggest change was to rewrite the new process plugin, field_bundle.

quietone’s picture

Found two instances of an extra full stop.

Sseto’s picture

I'm also getting this issue. I tried applying the patch from #65, but I'm getting an error:

- Applying patches for drupal/core
https://www.drupal.org/files/issues/2020-05-20/2565931-65.patch (Handle long comment bundle names)
Could not apply patch! Skipping. The error was: Cannot apply patch https://www.drupal.org/files/issues/2020-05-20/2565931-65.patch

Any idea why?

Thanks!

quietone’s picture

@Sseto, it needs a reroll.

Patch rerolled.

Status: Needs review » Needs work

The last submitted patch, 67: 2565931-67.patch, failed testing. View results

quietone’s picture

Status: Needs work » Needs review
FileSize
3.07 KB
29.05 KB

That was an error in the reroll of the D7 fixture.

Status: Needs review » Needs work

The last submitted patch, 69: 2565931-69.patch, failed testing. View results

quietone’s picture

Status: Needs work » Needs review
FileSize
1.37 KB
29.18 KB

Back to fixing tests and entity counts.

Sseto’s picture

Hi quietone,

I tried applying patch #69, #70, and #71 and I'm still getting the error.

- Applying patches for drupal/core
https://www.drupal.org/files/issues/2020-06-02/2565931-71.patch (Handle long comment bundle names)
Could not apply patch! Skipping. The error was: Cannot apply patch https://www.drupal.org/files/issues/2020-06-02/2565931-71.patch

shaktik’s picture

Hi @Sseto,

Could you try with fresh drupal Installation with 9.1.x version? if still getting the error please share the screenshot where you getting, Skipping or an error was: Cannot apply the patch.

Thanks,
Shakti

Sseto’s picture

Ah no wonder...I'm using D8...

azussman’s picture

This might not be the place to comment. But I am curious if there is a similar patch to Drupal 8. All of my search results keep on bringing me back to this one.

quietone’s picture

@azussman, no there isn't one for Drupal 8. If you need this for a local project you can just take the functional changes and skip the changes to the tests and fixtures. The changes to the tests and the fixtures are the most difficult part to reroll. Of course, you should do some manual testing to make sure it is working as expected for your Drupal 8 site(s).

mikelutz’s picture

Status: Needs review » Needs work
  1. +++ b/core/modules/field/src/Plugin/migrate/process/d7/FieldBundle.php
    @@ -0,0 +1,78 @@
    +/**
    + * Determines the bundle for a field.
    + *
    + * @MigrateProcessPlugin(
    + *   id = "field_bundle"
    + * )
    + */
    

    I think this needs more documentation as to how to use this plugin. I see the opening line of the transform function is [$entity_type, $bundle] = $value so I assume we need to pass in an array, but there is no documentation at the top of the process plugin.

  2. +++ b/core/modules/migrate_drupal/tests/fixtures/drupal6.php
    @@ -45854,6 +45854,22 @@
    +  'type' => 'a_thirty_two_character_type_name',
    

    I absolutely love that "a_thirty_two_character_type_name" is a 32 character type name.. Was part of this issue to ensure that if there was a second type name that started with "a_thirty_two_char" would not clash with the first one with a bundle of "comment_node_a_thirty_two_char", or something like that? Are we testing for that?

quietone’s picture

Status: Needs work » Needs review
FileSize
4.47 KB
29.12 KB

Before addressing #77, this needs a reroll.

quietone’s picture

77.1. Expanded the doc block with a description and examples.
77.2 Yes, I like that name as well. I don't think there is a need to confirm that name clashes are avoided because the migration is using make_unique_entity_field which is well tested.

mikelutz’s picture

Status: Needs review » Reviewed & tested by the community

Thanks for the extra documentation and the explanation as to why we don't need to test for clashing comment names!

catch’s picture

+++ b/core/modules/field/src/Plugin/migrate/process/d7/FieldBundle.php
@@ -0,0 +1,116 @@
+   */
+  public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
+    [$entity_type, $bundle] = $value;
+    if ($bundle === 'comment_node_forum') {
+      return 'comment_forum';
+    }
+    $lookup_result = NULL;
+    // For comment entity types get the destination bundle from the
+    // d7_comment_type migration.
+    if ($entity_type === 'comment') {
+      $value = preg_replace('/comment_node_/', NULL, $bundle);
+      $migration = 'd7_comment_type';
+      $lookup_result = $this->migrateLookup->lookup([$migration], [$value]);
+      $lookup_result = empty($lookup_result) ? NULL : reset($lookup_result[0]);
+    }
+    return $lookup_result ? $lookup_result : $bundle;
+  }
+

Could we not still use the static map for comment_node_forum/comment_forum in the migration itself somehow to override the behaviour, instead of doing it here?

quietone’s picture

We could, but I don't see the point. Doing so means the conversion of the bundle name is a two step process, a static map and process plugin, instead of just in one place, the process plugin. That alone adds some overhead. Then in field_bundle we either test for 'comment_forum' or we always run an extra migration_lookup. For me, the way it is now is the simplest for understanding and minimizes execution.

Just to be sure I tried it out. The following changes worked locally MigrateFieldInstance.php and MigrateFieldInstanceWidgetSettingsTest.php.

  bundle_mapped:
    plugin: static_map
    source: bundle
    bypass: true
    map:
      comment_node_forum: comment_forum
  bundle:
    plugin: field_bundle
    source:
      - entity_type
      - '@bundle_mapped'
  public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
    [$entity_type, $bundle] = $value;
    $lookup_result = NULL;
    // For comment entity types get the destination bundle from the
    // d7_comment_type migration.
    if ($entity_type === 'comment' && $bundle != 'comment_forum') {
      $value = preg_replace('/comment_node_/', NULL, $bundle);
      $migration = 'd7_comment_type';
      $lookup_result = $this->migrateLookup->lookup([$migration], [$value]);
      $lookup_result = empty($lookup_result) ? NULL : reset($lookup_result[0]);
    }
    return $lookup_result ? $lookup_result : $bundle;
catch’s picture

We could, but I don't see the point.

It would mean that the generic field_bundle plugin wouldn't need to special case comment module - that'd be the only reason to do it.

quietone’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
1.85 KB
30.3 KB

Sort of see your point and I do like to use the pipeline instead of a process plugin. For me, this is an exception for the reasons stated above (and influenced by the pain of migrating fields in Commerce Migrate).

I have made a patch and will let whoever reviews this make the choice. That is, assuming the tests pass.

heddn’s picture

Status: Needs review » Reviewed & tested by the community

I don't feel strongly one way or the other. Adding to yaml is feels cleaner. RTBC #84.

quietone’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs reroll

Sadly, needs a reroll. From the error message it looks suitable for a novice.

KapilV’s picture

Assigned: Unassigned » KapilV
KapilV’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
30.3 KB

Hear a reroll patch.

KapilV’s picture

Assigned: KapilV » Unassigned
quietone’s picture

FileSize
342 bytes

@kapilkumar0324, thanks for the reroll. It helps reviewers to have an interdiff, or diff, for rerolls. See Creating an interdiff. And if for any reason you think a diff is not necessary please add a comment staring why one is not included (and yes, I forgot to do that myself sometimes).

I've added a diff for the reroll. It looks good to me so I support this going back to RTBC.

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.

benjifisher’s picture

Status: Needs review » Reviewed & tested by the community

I did not review the patch as a whole, but I did compare the patches in #84 and #88. The only difference is one line of context, as shown in the diff attached to #90.

I am setting the status back to RTBC based on the review in #85.

quietone’s picture

quietone’s picture

Re-uploading the patch from #88 so that testing happens on 9.2.x not 9.1.

benjifisher’s picture

Issue summary: View changes
Issue tags: +Needs reroll, +Novice

It looks as though the patch needs a reroll. That is usually a Novice task, so I am adding the tag for that.

If you stick to the patch workflow, then please attach a diff (not an interdiff). See What about rerolled patches?.

You could also create an issue fork. Sometimes a change can be merged: the easy case of a reroll.

benjifisher’s picture

Status: Reviewed & tested by the community » Needs work
anushrikumari’s picture

Assigned: Unassigned » anushrikumari
anushrikumari’s picture

Assigned: anushrikumari » Unassigned
Status: Needs work » Needs review
FileSize
29.68 KB

Rerolled patch #88

Status: Needs review » Needs work

The last submitted patch, 98: 2565931-98.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

cosolom’s picture

Status: Needs work » Needs review

The patch #98 working fine for me. Failed test not related to the issue

quietone’s picture

@anushrikumari, thanks for the reroll. Can you add the diff for the reroll as asked for in #95.

benjifisher’s picture

Status: Needs review » Needs work
  1. I will ask the testbot to retest the patch in #98. It is good to have an opinion that it was an unrelated failure (and we do see those from time to time) but it is also good to get confirmation from the bot.
  2. The testbot also shows three coding-standard violations. Search https://www.drupal.org/pift-ci-job/1904506 for "coding standards messages".
  3. Either create an issue fork or attach a diff (not an interdiff) comparing to the patch in #88. See #95 for a link to instructions.

I am setting the status to NW for (2) and (3). This is still a Novice task.

sokru’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
29.56 KB
6.74 KB

Should fix the coding standard issues.

Status: Needs review » Needs work

The last submitted patch, 103: 2565931-103.patch, failed testing. View results

quietone’s picture

Status: Needs work » Needs review
Issue tags: -Novice
FileSize
1.25 KB
29.63 KB

@sokru, thanks for the reroll.

This changes the value passed to the lookup to a string, not an array. The array was causing an exception when the plugin was not found because the error message correctly assumes the migration id is a string when adding it to the error message.

quietone’s picture

An unused use statement crept into the previous patch.

benjifisher’s picture

Status: Needs review » Needs work

Comparing the patches in #88 and #106, I see a few differences:

  1. The patch in #88 added a line to both the D6 and D7 versions of MigrateCommentTypeTest.php, and the patch in #106 adds a line to the D7 version only. Is that on purpose?
  2. A line of context in that file. I guess that is why we need the reroll.
  3. An updated comment and the change explained in #105.
  4. A stray space was removed from the D7 fixture.

Of these, (2) and (4) look like improvements, and (1) looks like an accident. (Did the D6 version of that file also have a conflict?)

I wonder about the explanation in #105. The line in question (version from #88) is

+      $lookup_result = $this->migrateLookup->lookup([$migration], [$value]);

The migrateLookup property is injected from the migrate.lookup: service. Checking MigrateLookupInterface, the first parameter for lookup() can be either a string or an array of strings.

Where is the error message generated? (I guess the answer to that starts with looking at the failing test, but if you have already done that then I do not have to repeat the effort.) I think we may need a follow-up issue to fix that error message.

quietone’s picture

Status: Needs work » Needs review
FileSize
592 bytes
30.32 KB

From 107,

1. Sorry, I did notice that the reroll in 106 had removed the line from the d6 version of the test but I forgot to go back and fix that. The test is restored now in this patch.

Now to explain why the migration_id to the migrate lookup service should be a string in this case. The error in DoubleSlashTest when the first parameter is an array, $lookup_result = $this->migrateLookup->lookup([$migration], [$value]); is:

1) Drupal\Tests\migrate_drupal_ui\Functional\d7\DoubleSlashTest::testMigrateUpgradeExecute
Exception: Notice: Array to string conversion
Drupal\Component\Plugin\Exception\PluginNotFoundException->__construct()() (Line: 22)

That is because PluginNotFoundException expects the first parameter to be a string.

The MigrateLookup service needs to use a custom message and handle an array of migration ids, instead of doing this:

  public function lookup($migration_id, array $source_id_values) {
    $results = [];
    $migrations = $this->migrationPluginManager->createInstances($migration_id);
    if (!$migrations) {
      throw new PluginNotFoundException($migration_id);
    }

The fix here is valid but we need a followup one for the lookup service. I plan to check for an existing issue, which I can do later.

quietone’s picture

Didn't find an existing issue so made a followup as per #108, #3187386: Use a custom error message for PluginNotFoundException in the migratelookup service.

benjifisher’s picture

Status: Needs review » Reviewed & tested by the community

I compared the current patch (#108) to the one in #88. I now see changes 2, 3, 4, but not 1 (referring to the list in #107). The line of context (item 2) has changed for both the D6 and D7 versions of MigrateCommentTypeTest.php.

Based on the review in #85 and the changes since then, I am satisfied. RTBC

Thanks for the further explanation and the follow-up issue. I agree with the decision to work around that bug here instead of postponing on the new issue.

  • catch committed 5fb9795 on 9.2.x
    Issue #2565931 by quietone, jofitz, shaktik, sokru, mikeryan, clemens....

  • catch committed 9e009ed on 9.1.x
    Issue #2565931 by quietone, jofitz, shaktik, sokru, mikeryan, clemens....
catch’s picture

Version: 9.2.x-dev » 9.1.x-dev
Status: Reviewed & tested by the community » Fixed

Have reviewed this a few times, and always think I've found an issue, then talk myself out of it, then leave it for a while, then do the same thing again. I think this is fine so committed/pushed to 9.2.x and cherry-picked to 9.1.x, thanks!

Status: Fixed » Closed (fixed)

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

Wim Leers’s picture

+++ b/core/modules/field/migrations/d7_field_instance.yml
@@ -19,12 +19,17 @@ process:
-  bundle:
+  bundle_mapped:
     plugin: static_map
     source: bundle
     bypass: true
     map:
       comment_node_forum: comment_forum
+  bundle:
+    plugin: field_bundle
+    source:
+      - entity_type
+      - '@bundle_mapped'

FYI: This change broke the Paragraphs migration in contrib! 😞

See #3203739: Paragraphs migrations broken in Drupal >=9.1.4 for details + fix.