I've run into an issue when running a product_variation migration and then trying to roll it back prior to doing a product migration. The error I receive is:
[error] Symfony\Component\Routing\Exception\InvalidParameterException: Parameter "commerce_product" for route "entity.commerce_product_variation.add_form" must match "[^/]++" ("" given) to generate a corresponding URL. in Drupal\Core\Routing\UrlGenerator->doGenerate() (line 204 of /var/www/html/web/core/lib/Drupal/Core/Routing/UrlGenerator.php).
I've discovered that in my case, this appears to be caused by product_variations that do not yet have a product_id value in the commerce_product_variation_field_data table.
This is a custom migration that is based on the commerce_migrate_commerce commerce1_product_variation.yml configuration. Like this config, the product_id field isn't populated during the product_variation migration, rather is it populated when the product migration is run.
In my case, I found that some of my migrated product_variation entities were orphaned. That is, after I migrated product_variations and products, a small number of product_variations still didn't have product_id values.
I verified that if I tried deleting these orphaned product_variations using Drupal Console, I could reproduce the same error.
$ drupal entity:delete commerce_product_variation 2339
[ERROR] Parameter "commerce_product" for route "entity.commerce_product_variation.add_form" must match "[^/]++" (""
given) to generate a corresponding URL.
However, if I manually removed the orphaned product_variations from the database using
DELETE FROM commerce_product_variation WHERE variation_id IN (SELECT variation_id FROM commerce_product_variation_field_data WHERE product_id IS NULL);
DELETE FROM migrate_map_product_variation WHERE destid1 IN (SELECT variation_id FROM commerce_product_variation_field_data WHERE product_id IS NULL);
DELETE FROM commerce_product_variation__attribute_size_oils WHERE entity_id IN (SELECT variation_id FROM commerce_product_variation_field_data WHERE product_id IS NULL);
DELETE FROM commerce_product_variation_field_data WHERE product_id IS NULL;
I could then run drush mr product_variation
without any errors.
So, at this point in time, for my particular project, I'm going to create a custom source plugin to avoid migrated orphaned product_variation entities.
Based on what I'm seeing, I'm thinking that running a product_variation rollback prior to running a product migration will always fail, regardless of if there are any orphans (due to missing product_id values).
-mike
Comment | File | Size | Author |
---|---|---|---|
#27 | commerce-product-variation-delete-3036565-27.patch | 2.38 KB | NickDickinsonWilde |
| |||
#27 | commerce-product-variation-delete-3036565-27-test-only.patch | 1.07 KB | NickDickinsonWilde |
#16 | 3036568-test-only.patch | 1.89 KB | eiriksm |
#13 | 3036568.patch | 1.46 KB | eiriksm |
| |||
#3 | 3036568-3-fail.patch | 1.3 KB | quietone |
Comments
Comment #2
heddnWe don't have any tests for product variation or order item rollback. Only for product and order rollback. I think the first thing would be to add some level of tests, using the order and product rollback tests as an example.
Comment #3
quietone CreditAttribution: quietone at Acro Commerce commentedGood point. And when working on it I found that the product rollback test is quite right either because the migrations need to be expanded first. There is a fail patch to demonstrate the problem.
Then a product variation rollback test is added.
Comment #5
heddnSo, based on the IS it looks like we need to do some more to recreate the situation seen by Mike.
Comment #6
quietone CreditAttribution: quietone at Acro Commerce commentedThe test does run the product variation migration, then a rollback of product variations without errors. The product migration is not run at all.
I migrated the ck2 database using the UI, then used drush to rollback product variations. It worked for a while then stopped working on 'drinks'.
I debugged for a bit and got lost is routing, which I don't know so stopped. After that I was curious if this was limited to 'drinks'. I did many combinations of import and rollback of both products and product variations. And in the end 'drinks' always fails, 'storage devices' started to fail but 'tops' continued to import and rollback successfully. Also. once the error appears I wasn't able to use drush to get rid of it on rollback.
Comment #7
ultimikeI have a small .csv dataset and custom migration where this is easily reproducible. Assuming my client's permission, I'd be happy to share it with both of you directly.
Let me know.
thanks,
-mike
Comment #8
lithiumlab CreditAttribution: lithiumlab commentedIm also experiencing the same issue when rolling back a commerce product variation migration.
Comment #9
Plankje CreditAttribution: Plankje commentedI have observed that the same exception may be thrown when trying to remove an orphan product variation in a non-migration context, i.e. a custom module.
Comment #10
jonathanshawI've hit #9 also, so I think the bug here is upstream: Commerce should allow deleting variations that have lost their product reference.
Comment #11
andyg5000WARNING: Super janky hack incoming.
If you need to repeatedly roll back migrations or bulk delete orphaned product variations, throw this in the Drupal\commerce_product\Entity\ProductVariation
I don't believe the product id even has to exist, but gets around the route generator limitation since a value now exists.
Comment #12
anpel CreditAttribution: anpel commented@andyg5000 Super janky hack from #11 works fine, I was just able to rollback variations with no issues.
Comment #13
eiriksmIf the problem is to reproduce the problem, here is a super easy way to reproduce it:
Just testing if this patch passes first, in then it should be super easy to write a test.
Comment #14
ahimsauzi@andyg5000 #11 works for me while debugging migration. I love it when I get to hack Drupal :)
Comment #15
AjitSThe patch provided in #13 solves the issue. Thank you also for providing steps to reproduce!
Comment #16
eiriksmOK so here is a test only patch (that should fail) and a complete patch.
Just for reference, this only happens if you have the module menu_link_content enabled, which probably is the case for a lot of commerce sites.
So removing the needs tests tag.
Comment #18
jonathanshawNice.
Comment #19
Krzysztof Domański1. There may be less code.
2. Unused use statement.
3. There may be less code.
4. Typo van/can.
Comment #20
Krzysztof DomańskiFixed #19 and RTBC+1
Comment #21
jonathanshawRTBC +1
Comment #22
yoerioptr CreditAttribution: yoerioptr commentedGreat patch from Krzysztof, problems solved for the issues above. There are still some issues when dealing with multi language.
`Symfony\Component\Routing\Exception\InvalidParameterException: Parameter "commerce_product" for route "entity.commerce_product_variation.content_translation_..." must match "[^/]++" ("" given) to
generate a corresponding URL. in Drupal\Core\Routing\UrlGenerator->doGenerate() (line 204 of`
This error gets thrown for the routes: content-translation-overview, add, edit and delete.
Comment #23
yoerioptr CreditAttribution: yoerioptr commentedComment #24
yoerioptr CreditAttribution: yoerioptr commentedComment #25
nno CreditAttribution: nno commentedWorks great. Thank you!
Comment #26
bojanz CreditAttribution: bojanz at Centarro commented1. The ProductVariationMenuLinkTest is super small, let's merge it into the ProductVariationTest, which is a kernel test covering the entity in question.
2.
It's a bit unfortunate that we're hardcoding the route names here.
Can't we do something like:
Or maybe even something as extreme as:
Comment #27
NickDickinsonWildeGiven that the next existing chunk of code was:
and those weren't in the list of route names, I moved it to the most extreme, just does this have a product ID or not.
Also adjusted the test as per your comments.
Comment #29
bojanz CreditAttribution: bojanz at Centarro commentedTweaked #27 and committed. Thanks, everyone!
Comment #30
Krzysztof DomańskiThis change needs a comment. In the future, we will not know why this module has been added.
After deleting this line, the test will still pass, but without 'menu_link_content' this test does not verify that everything is still working.
Comment #31
Krzysztof DomańskiOk, I see the comment in commit https://git.drupalcode.org/project/commerce/commit/7bf1a4e
Comment #33
SocialNicheGuru CreditAttribution: SocialNicheGuru commentedalso it looks like it only works with default product_variation.
what happens if a custom variation type is used?