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)
Comment | File | Size | Author |
---|---|---|---|
#108 | 2565931-108.patch | 30.32 KB | quietone |
#108 | interdiff-106-108.txt | 592 bytes | quietone |
#106 | 2565931-106.patch | 29.57 KB | quietone |
#106 | interdiff-103-106.txt | 995 bytes | quietone |
#105 | 2565931-105.patch | 29.63 KB | quietone |
Comments
Comment #2
mikeryanThis 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:
Downstream, I'm also getting these errors, not sure whether they're a consequence of this issue or a separate issue:
Comment #5
mitrpaka CreditAttribution: mitrpaka as a volunteer commentedChecked if patch needed a re-roll. Offset spotted. Patch file updated.
Comment #7
heddnNow that dedupe has been renamed, this needs a re-roll.
Comment #8
jofitz CreditAttribution: jofitz at ComputerMinds commentedUpdated references to plugins "dedupe_entity" ("make_unique_entity_field") and "migration" ("migration_lookup").
Comment #11
jofitz CreditAttribution: jofitz at ComputerMinds commentedPatch in #8 no longer applies. Re-rolled.
Comment #12
jofitz CreditAttribution: jofitz at ComputerMinds commentedCorrect invalid YAML.
Comment #13
heddnIf 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.
Comment #14
jofitz CreditAttribution: jofitz at ComputerMinds commentedReduced the number of characters from 32 to 30, as suggested.
Fixed bugs in a couple of tests.
Comment #15
jofitz CreditAttribution: jofitz at ComputerMinds commentedMany tests will still fail because the new markup to obtain the bundle:
...fails if the bundle is "user". I have been unable to come up with a solution. Any suggestions?
Comment #17
NiklasBr CreditAttribution: NiklasBr commentedAdding Drupal 6 tag because this happens on 8.5.x when migrating from 6.x as well.
Comment #18
NiklasBr CreditAttribution: NiklasBr commentedWe 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?
Comment #19
quietone CreditAttribution: quietone as a volunteer commentedThe original report is for D7->D8, so adding that tag.
Comment #21
clemens.tolboomSee 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.
Comment #22
clemens.tolboomI 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
and this patch
Comment #23
wturrell CreditAttribution: wturrell commentedHere'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?
Comment #24
savkaviktor16@gmail.com CreditAttribution: savkaviktor16@gmail.com at Skilld commentedComment #28
quietone CreditAttribution: quietone as a volunteer commentedAdd related issue
Comment #30
Summit CreditAttribution: Summit commentedHi,
I also bumped in to this error:
Is there any news that this can be fixed, or do I need to alter my nodetypes to smaller amount of characters?
greetings, Martijn
Comment #31
steinmb CreditAttribution: steinmb as a volunteer commentedI worked around the problem by not migrating the config. Manually created the D8/9 node bundles and only migrated the content.
Comment #32
quietone CreditAttribution: quietone as a volunteer commentedI 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.
Comment #34
clemens.tolboomShould we really (care about) migrate D6 to D9?
Comment #35
quietone CreditAttribution: quietone as a volunteer commentedRemoved 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.
Comment #37
quietone CreditAttribution: quietone as a volunteer commentedThis 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.
Comment #39
quietone CreditAttribution: quietone as a volunteer commentedDidn'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.
Comment #41
quietone CreditAttribution: quietone as a volunteer commentedFixing some more tests and fixing coding standard issues.
Comment #42
quietone CreditAttribution: quietone as a volunteer commentedComment #44
quietone CreditAttribution: quietone as a volunteer commentedStill working on the tests.
Comment #46
quietone CreditAttribution: quietone as a volunteer commentedA few more test fixes.
Comment #48
quietone CreditAttribution: quietone as a volunteer commentedAdd assertions to D7 field tests and add changes to the D6 fixture and d6 tests.
Comment #50
quietone CreditAttribution: quietone as a volunteer commentedUnrelated fail, retesting.
Comment #51
quietone CreditAttribution: quietone as a volunteer commentedThe 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.
Comment #53
quietone CreditAttribution: quietone as a volunteer commentedChange 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.
Comment #55
quietone CreditAttribution: quietone as a volunteer commentedCorrect the name of the new node type in the drupal6 fixture, add more d6 tests.
Comment #57
shaktikComment #58
shaktikComment #59
shaktikAdded interdiff txt file for #57 to fixing test cases.
Comment #61
shaktikI am working on it.
Comment #62
shaktikComment #63
shaktikHi @quietone,
Fixed test case issue, Kindly review.
Comment #64
quietone CreditAttribution: quietone as a volunteer commented@shaktik, thank you.
Did a bit of cleanup and add comments. The biggest change was to rewrite the new process plugin, field_bundle.
Comment #65
quietone CreditAttribution: quietone as a volunteer commentedFound two instances of an extra full stop.
Comment #66
Sseto CreditAttribution: Sseto commentedI'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!
Comment #67
quietone CreditAttribution: quietone as a volunteer commented@Sseto, it needs a reroll.
Patch rerolled.
Comment #69
quietone CreditAttribution: quietone as a volunteer commentedThat was an error in the reroll of the D7 fixture.
Comment #71
quietone CreditAttribution: quietone as a volunteer commentedBack to fixing tests and entity counts.
Comment #72
Sseto CreditAttribution: Sseto commentedHi 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
Comment #73
shaktikHi @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
Comment #74
Sseto CreditAttribution: Sseto commentedAh no wonder...I'm using D8...
Comment #75
azussman CreditAttribution: azussman commentedThis 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.
Comment #76
quietone CreditAttribution: quietone as a volunteer commented@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).
Comment #77
mikelutzI 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.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?
Comment #78
quietone CreditAttribution: quietone as a volunteer commentedBefore addressing #77, this needs a reroll.
Comment #79
quietone CreditAttribution: quietone as a volunteer commented77.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.
Comment #80
mikelutzThanks for the extra documentation and the explanation as to why we don't need to test for clashing comment names!
Comment #81
catchCould 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?
Comment #82
quietone CreditAttribution: quietone as a volunteer commentedWe 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.
Comment #83
catchIt 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.
Comment #84
quietone CreditAttribution: quietone as a volunteer commentedSort 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.
Comment #85
heddnI don't feel strongly one way or the other. Adding to yaml is feels cleaner. RTBC #84.
Comment #86
quietone CreditAttribution: quietone as a volunteer commentedSadly, needs a reroll. From the error message it looks suitable for a novice.
Comment #87
KapilV CreditAttribution: KapilV as a volunteer and commentedComment #88
KapilV CreditAttribution: KapilV as a volunteer and commentedHear a reroll patch.
Comment #89
KapilV CreditAttribution: KapilV at Innoraft for Drupal Care commentedComment #90
quietone CreditAttribution: quietone as a volunteer commented@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.
Comment #92
benjifisherI 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.
Comment #93
quietone CreditAttribution: quietone as a volunteer commentedComment #94
quietone CreditAttribution: quietone as a volunteer commentedRe-uploading the patch from #88 so that testing happens on 9.2.x not 9.1.
Comment #95
benjifisherIt 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.
Comment #96
benjifisherComment #97
anushrikumari CreditAttribution: anushrikumari at OpenSense Labs commentedComment #98
anushrikumari CreditAttribution: anushrikumari at OpenSense Labs commentedRerolled patch #88
Comment #100
cosolom CreditAttribution: cosolom commentedThe patch #98 working fine for me. Failed test not related to the issue
Comment #101
quietone CreditAttribution: quietone as a volunteer commented@anushrikumari, thanks for the reroll. Can you add the diff for the reroll as asked for in #95.
Comment #102
benjifisherI am setting the status to NW for (2) and (3). This is still a Novice task.
Comment #103
sokru CreditAttribution: sokru as a volunteer commentedShould fix the coding standard issues.
Comment #105
quietone CreditAttribution: quietone as a volunteer commented@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.
Comment #106
quietone CreditAttribution: quietone as a volunteer commentedAn unused use statement crept into the previous patch.
Comment #107
benjifisherComparing the patches in #88 and #106, I see a few differences:
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
The
migrateLookup
property is injected from themigrate.lookup:
service. Checking MigrateLookupInterface, the first parameter forlookup()
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.
Comment #108
quietone CreditAttribution: quietone as a volunteer commentedFrom 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: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:
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.
Comment #109
quietone CreditAttribution: quietone as a volunteer commentedDidn't find an existing issue so made a followup as per #108, #3187386: Use a custom error message for PluginNotFoundException in the migratelookup service.
Comment #110
benjifisherI 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.
Comment #113
catchHave 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!
Comment #115
Wim LeersFYI: This change broke the Paragraphs migration in contrib! 😞
See #3203739: Paragraphs migrations broken in Drupal >=9.1.4 for details + fix.