Problem/Motivation
When trying to migrate a D7 site with field_collections to D8, sometimes field instances fail to migrate because the process pipelines remap the bundle names incorrectly. For instance, a D7 field_collection named 'field_my_field_collection' should map to the paragraphs bundle 'my_field_collection', but when processing certain field instance rows, it may become 'ld_collection' instead (removing 12 characters instead of only 6), and yield an error like 'Missing bundle entity, entity type paragraphs_type, entity id ld_collection' (or a couple other variations).
Steps to reproduce
I'm not sure how to reproduce this, other than a specific site, but other users have had similar reports. It may be that a combination of field_collection, field_group, and possibly sharing field instances of the same base field (of type field collection) trigger the issue.
See https://www.drupal.org/project/paragraphs/issues/2897021#comment-12491141 for instance, although significant progress has been made since then.
Proposed resolution
Currently, the MigrationPluginsAlterer class iterates over process pipelines and adds a substr plugin. I could not fully comprehend this with my level of comfort on both paragraphs and the whole migration framework, so there is almost certainly a deeper issue that my proposed solution won't address.
I made a slight variation of the substr plugin, which checks that the string actually begins with 'field_' before returning it, and returns the input as-is if it doesn't start with the proper prefix.
This clearly isn't a perfect solution, as it could still have failure cases if someone had named their field collection 'field_field_something', but did fix the issue for my site.
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | paragraphs-n3192993-5.patch | 1.83 KB | damienmckenna |
| #5 | paragraphs-n3192993-5.interdiff.txt | 943 bytes | damienmckenna |
| paragraphs-strip-field-prefix.patch | 1.85 KB | noahadler |
Comments
Comment #2
noahadler commentedComment #3
damienmckennaComment #4
damienmckennaThis fixes the problem for me, waiting to see what the testbot says.
Comment #5
damienmckennaMinor coding standards improvements.
Comment #6
damienmckennaPatch #5 resolves the problem for me, but I shouldn't RTBC my own patch.
Comment #7
bob.hinrichs commentedRan into this same problem, thought patch is not applying to Drupal 9.1.4 but it was my fault, real problem was I had to reference in drupal/paragraphs, not core..
Comment #8
sseto commentedHey @DamienMckenna,
I can confirm it worked for me when migrating D7 to D8. I got the error when I tried migrating without the patch from #5.
When re-migrating the site WITH the patch, there was no error.
Thanks for fixing this issue :)
Comment #9
wim leersNice catch —
\Drupal\migrate\Plugin\migrate\process\Substrindeed is unable to deal with conditionality: i.e. only return a substring if a certain prefix is present.Comment #10
wim leersFYI marked #3176058: Field Collections migration resulting in multiple incorrect bundle names a duplicate. Bumping to because multiple people are reporting this independently.
Comment #11
luksakWorks for me. Thank you!
Comment #12
gbotis commentedI had the same problem and #5 patch worked for me as well. If you migrate to D9 the patch will be not be applied if you use stable 1.12 version, you should use the dev version.
Comment #13
wim leersFor people who had this problem: were you using
Migrationconfig entities? i.e. did you generate/export migration definitions usingmigrate_upgrade?Comment #14
gbotis commented@wim-leers, yes that was exactly my case
Comment #15
damienmckennaYes, I did too.
Comment #16
wim leersThanks, both of you — that confirms @huzooka's theory that this only occurs when you're applying this processing multiple times, which is only the case for
migrate_upgrade, because it first generates the migration plugins, then generates new ones as config, hence causing double processing.Comment #17
hani.atalla commentedI ran the migration steps to migrate a D7 site to D9 and the D7 had a couple of collection fields associated to a couple of content types. The "drush mim upgrade_d7_field_collection_type" step runs successfully and I see the paragraphs getting created without the fields. Then I run "drush mim upgrade_d7_field" with no errors. Then I run "drush mim upgrade_d7_field_instance" and that successfully runs except I get a couple of errors unrelated to collections/paragraphs and I see the paragraphs fields getting added (among other fields) to the relevant node that uses that paragraph and it looks good to me.
Then I run "drush mim upgrade_d7_field_formatter_settings" and this when I get the error:
Missing bundle entity, entity type paragraphs_type, entity id allout. (/sites/drupal/digital-d9/docroot/core/lib/Drupal/Core/Entity/EntityType.php:877)
Now patch 5 from this thread doesn't apply because I am using Paragraphs Version: 8.x-1.12 and that version doesn't have the "/src/MigrationPluginsAlterer.php" file
I go ahead and run "drush mim upgrade_d7_node_complete_
. and I don't get any errors. But when I edit a node that of that type, all the fields values are correctly populated except for the paragraphs fields, nothing there.
Appreciate any help and my apology if I added this in the wrong thread.
Thanks.
Hani
Comment #18
labboy0276 commented@hani.atalla I was getting similar issues as you were, I had to tweak a couple migration yamls as follows:
upgrade_d7_field_formatter_settings & upgrade_d7_field_instance_widget_settings, Under bundle I had to remove the substr plugin under the paragraphs_process_on_value process and now it looks like:
For this upgrade_d7_field_instance yaml, the bundle process should look like this now:
Comment #19
faubulous commentedHi guys!
I am having the same issue as #17 (@hani.atalla)(on version 8.x-1.12). Initially I ran into the same issues with the missing bundle entity ids, but I managed to workaround it by hacking the
paragraphs_process_on_valueplugin to remove the "field_" prefix from the bundle name in the transform method conditionally:This makes the import routine run without errors. However, after migrating I do not see any data on the migrated fields. All the corresponding entries in the database are empty. Is there anything I am missing?
I'd appreciate any help! :)
Comment #20
huzookaI think we should use target bundle lookup for the bundle IDs. I did the same for #2977853: [PP-4] Multifield to Paragraphs migration, and just released the plugin with test coverage at #3225877: Copy TargetBundleLookup (from dgo.to/2977853) to Migrate Magician and add test coverage.
Comment #21
huzookaCould you please check #3226658: Guarantee the uniqueness of the migrated paragraph types?
I bet it fixes this issue as well (and a bit more as well).
Comment #22
berdirConfused by recent comments. Is this now RTBC or not?
Comment #23
vlad.dancerI can't set the issue to RTBC. It doesn't work for me.
Instead I've re-rolled and applied patch from #3226658: Guarantee the uniqueness of the migrated paragraph types and prefix removal is not occures anymore.
But now I don't see any fields neither on a Manage fields page nor on the Manage form display page.
Indeed the paragraph fields tables are created in database.
Comment #24
eojthebraveFWIW the patch in #5 worked for me. My example has a Drupal 7 content type with both paragraphs and field collection fields. And uses migrate plus / migrate upgrade. Without the patch in #5 fields from the field collections where not properly migrated because the entity type name gets clobbered. With the patch in #5 everything is working.
I can't speak to whether this approach or the one in the other issues is better.
Comment #25
natefollmer commentedIs there anywhere else the field_ could be stripped from field collection migrations? I've applied #5, changed my yml files to remove the substr process and I'm still having issues. As soon as I run the field instance migration I'm getting errors like
a:3:{s:12:"%entity_type";s:9:"paragraph";s:7:"%bundle";s:2:"rd";s:6:"%field";s:24:"field_bio_card_org_title";}in watchdog. This causes the entire site to WSOD. If I rollback field instance, then the site is back, but obviously there are no fields attached to any content types or paragraphs.Comment #26
phannphong commentedI confirm the patch in #5 can fix the issue when the prefix `field_` is removed.
Comment #27
ali rizvi commentedhi,
I'm migrating d7 to d9 and i have to migrate field collections to paragraphs and in field collections i have fields which has field type 'entity reference' and that reference's to field collection and view of field collection
drush mim upgrade_d7_field_collection_type
This creates the Paragraph Types from Field Collection
drush mim upgrade_d7_field_collection_field_name
This creates field instance ONLY
drush mim upgrade_d7_node_type
"Imports node types, This creates the Content Types - CCK structure"
and when i try to import field of cck using this
drush mim upgrade_d7_field
33/107 [========>-------------------] 30% [error] The "field_collection_item" entity type does not exist. (/opt/httpd/htdocs/sites/vecplerpd9/master/web/core/lib/Drupal/Core/Entity/EntityTypeManager.php:139)
[error] The "field_collection_item" entity type does not exist.
[notice] Processed 107 items (101 created, 0 updated, 6 failed, 0 ignored) - done with 'upgrade_d7_field'
cck fields are not getting migrated because of field collections
any help would be appreciated
Comment #28
alison#5 fixed the issue for me (PHEW).
Comment #29
berdirLooks like it works for several people but others still have issues. Committed this, if you still have issues then open a new issue (see also comment #23).
Comment #32
shafiqhossain commentedI am still facing the issue with redundant "field_" prefix while migrating.
We have a field collection named as "field_field_rep_products_price". While migrating its breaks on "upgrade_d7_field_instance". its searching an entity id "rep_products_price" which is NOT correct but in D10, its actually created a paragraph_type with correct name
"paragraphs.paragraphs_type.field_rep_products_price". As a results migration breaks.