Magento2: Magento 2.4 Upgrade issue Unable to apply data patch Magento\CatalogUrlRewrite\Setup\Patch\Data\UpdateUrlKeyForProducts

Created on 3 Aug 2020  ·  44Comments  ·  Source: magento/magento2

Preconditions (*)

  1. Magento 2.4.0

Steps to reproduce (*)

  1. Composer upgrade from 2.3.4 to 2.4.0
  2. php bin/magento setup:upgrade

Expected result (*)

  1. Successful upgrade

Actual result (*)

Module 'Magento_EavGraphQl':                                                                                                                                                                                                                  
Module 'Magento_Cms':                                                                                                                                                                                                                         
Module 'Magento_CatalogImportExport':                                                                                                                                                                                                         
Module 'Magento_Catalog':                                                                                                                                                                                                                     
Module 'Magento_CatalogInventory':                                                                                                                                                                                                            
Module 'Magento_Rule':                                                                                                                                                                                                                        
Module 'Magento_Payment':                                                                                                                                                                                                                     
Module 'Magento_CatalogRuleGraphQl':                                                                                                                                                                                                          
Module 'Magento_CatalogRule':                                                                                                                                                                                                                 
Module 'Magento_CatalogUrlRewrite':                                                                                                                                                                                                           
Unable to apply data patch Magento\CatalogUrlRewrite\Setup\Patch\Data\UpdateUrlKeyForProducts for module Magento_CatalogUrlRewrite. Original exception message: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a c
hild row: a foreign key constraint fails (`m24`.`catalog_product_entity_varchar`, CONSTRAINT `CAT_PRD_ENTT_VCHR_ENTT_ID_CAT_PRD_ENTT_ENTT_ID` FOREIGN KEY (`entity_id`) REFERENCES `catalog_product_entity` (`entity_id`) ON DELETE CA), q
uery was: INSERT  INTO `catalog_product_entity_varchar` (`value_id`,`value`) VALUES (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?
, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), 
(?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?)
, (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, 
?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?
, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), 
(?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?)
, (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, 
?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?
, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), 
(?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?)
, (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, 
?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?
, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), 
(?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?)
, (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, 
?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?
, ?), (?, ?), (?, ?), (?, ?), (?, ?) ON DUPLICATE KEY UPDATE `value` = VALUES(`value`)                                                                                                                                                        

Please provide Severity assessment for the Issue as Reporter. This information will help during Confirmation and Issue triage processes.

  • [x] Severity: S0 _- Affects critical data or functionality and leaves users without workaround._
  • [ ] Severity: S1 _- Affects critical data or functionality and forces users to employ a workaround._
  • [ ] Severity: S2 _- Affects non-critical data or functionality and forces users to employ a workaround._
  • [ ] Severity: S3 _- Affects non-critical data or functionality and does not force users to employ a workaround._
  • [ ] Severity: S4 _- Affects aesthetics, professional look and feel, “quality” or “usability”._
P1 PR in progress Reported on 2.3.4 S1

Most helpful comment

We had the same issue when upgrading from 2.3.4 to 2.4.1.
As someone else has mentioned, applying this pull request as a patch seemingly works.

All 44 comments

Hi @sunel. Thank you for your report.
To help us process this issue please make sure that you provided the following information:

  • Summary of the issue
  • Information on your environment
  • Steps to reproduce
  • Expected and actual results

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento give me 2.4-develop instance - upcoming 2.4.x release

For more details, please, review the Magento Contributor Assistant documentation.

Please, add a comment to assign the issue: @magento I am working on this


  • Join Magento Community Engineering Slack and ask your questions in #github channel.

    :warning: According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.

:clock10: You can find the schedule on the Magento Community Calendar page.

:telephone_receiver: The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, please join the Community Contributions Triage session to discuss the appropriate ticket.

:movie_camera: You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel

:pencil2: Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

I can confirm we are experiencing the same issue when trying to upgrade from CE 2.3.5-p2 to 2.4.0

Wonder if this should be update on duplicate instead of insert on duplicate.
https://github.com/magento/magento2/blob/2.4.0/app/code/Magento/CatalogUrlRewrite/Setup/Patch/Data/UpdateUrlKeyForProducts.php#L73

I tried this with no success unfortunately. Unrecognised class error or something similar

Can confirm issue. Upgrading from 2.3.5 to 2.4.

Any solution, we are stuck here

@moni921 for now you can disable and re-enable foreign key constrain

...php
$setup->getConnection()->query('SET @TEMPORARY_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=1');
$this->groupRepository->delete($customerGroup);
$setup->getConnection()->query('SET FOREIGN_KEY_CHECKS=IF(@TEMPORARY_FOREIGN_KEY_CHECKS=0, 0, 1)');
...

Can confirm issue. Upgrading from 2.3.5-p1 to 2.4.

For the update to succeed all keys should be included in the query.
Change lines according below in MagentoCatalogUrlRewrite\Setup\Patch\Data\UpdateUrlKeyForProducts:

@@ -58,7 +58,7 @@
         $table = $this->moduleDataSetup->getTable('catalog_product_entity_varchar');
         $select = $this->moduleDataSetup->getConnection()->select()->from(
             $table,
-            ['value_id', 'value']
+            ['entity_id', 'attribute_id', 'store_id', 'value_id', 'value']
         )->where(
             'attribute_id = ?',
             $this->eavSetup->getAttributeId($productTypeId, 'url_key')

For the update to succeed all keys should be included in the query.
Change lines according below:

@@ -58,7 +58,7 @@
         $table = $this->moduleDataSetup->getTable('catalog_product_entity_varchar');
         $select = $this->moduleDataSetup->getConnection()->select()->from(
             $table,
-            ['value_id', 'value']
+            ['entity_id', 'attribute_id', 'store_id', 'value_id', 'value']
         )->where(
             'attribute_id = ?',
             $this->eavSetup->getAttributeId($productTypeId, 'url_key')

Can you provide more details? Which file are you changing?

Hi @dharake
@BavoJanss is talking about file "UpdateUrlKeyForProducts.php" located in > vendor/magento/module-catalog-url-rewrite/Setup/Patch/Data

It worked for me!!
Thanks @BavoJanss

Hi @dharake
@BavoJanss is talking about file "UpdateUrlKeyForProducts.php" located in > vendor/magento/module-catalog-url-rewrite/Setup/Patch/Data

It worked for me!!
Thanks @BavoJanss

Thanks @vanvasten, glad it worked for you. Will try it out

Tagging @engcom-Echo in here, since he wrote that patch, maybe he has some more useful insights and can push for a quick fix to be added to Magento 2.4.1 or a hotfix to be released if it is deemed necessary 🙂

Please note that this patch is not working for commerce installations. entity_id is not a column name for commerce, it should be row_id instead.

I reported the same problem in ticket 29805, closed due to being duplicated to this one.

I am posting my solution to the issue below whilst Magento is taking time to push another update:

->

Further into the problem details, I debugged the installation and can see the following in your upgrade code:

Under vendor/magento/module-catalog-url-rewrite/Setup/Patch/Data/UpdateUrlKeyForProducts.php

You have:

Line-67 says:

$result = $this->moduleDataSetup->getConnection()->fetchAll($select);

This reads all details from the catalog_product_entity_varchar table, on my installation it loads over 8000 records.

Then you have a foreach look that is updating the values within the array:

$result[$key]['value'] = $this->urlProduct->formatUrlKey($item['value']);

So far so good,...

But then after the array is finished above, you are then re-inserting the same IDs into the database with the
insertOnDuplicate function that is known to throw an error if the record already exists:

foreach (array_chunk($result, 500, true) as $pathResult) {
    $this->moduleDataSetup->getConnection()->insertOnDuplicate($table, $pathResult, ['value']);
}

This means that the upgrade will NEVER succeed whenever there is data in an existing version.

I wonder,... have you guys tested this before launching v2.4 ?

The solution is to:

Please don't re-insert/update all values into the database from the array you just loaded as it causes performance problems, or upgrade too slow etc), rather, have a logic that says:

$OLD = $item['value'];
$NEW = $this->urlProduct->formatUrlKey($item['value']);

if ($OLD !== $NEW)
{
... update the database
}
Replace the insertOnDuplicate function with an UPDATE instead.

I hope this helps, I posted the following:

A) Exact issue
B) Exact files causing this issue
C) Code snippets on what to change to fix the issue

In other words, the existing logic of:

Read database values,
Do some changes (if any)
Re-Insert back into the database with the function that throws an exception/error if the value is there already
Of course would fail, mainly because the ID/Keys are already in the database.

The solution is to change (3) into (Update if the value change)... please remove the Insert function at the end of the Apply() function.

If you require any further information, then please let me know.

Kind Regards
Heider

For the update to succeed all keys should be included in the query.
Change lines according below in MagentoCatalogUrlRewrite\Setup\Patch\Data\UpdateUrlKeyForProducts:

@@ -58,7 +58,7 @@
         $table = $this->moduleDataSetup->getTable('catalog_product_entity_varchar');
         $select = $this->moduleDataSetup->getConnection()->select()->from(
             $table,
-            ['value_id', 'value']
+            ['entity_id', 'attribute_id', 'store_id', 'value_id', 'value']
         )->where(
             'attribute_id = ?',
             $this->eavSetup->getAttributeId($productTypeId, 'url_key')

why "entity_id" ?? that must be "row_id". e.g.:
['row_id', 'attribute_id', 'store_id', 'value_id', 'value']

@luka4 I believe it should be different for OS & EE versions.
All needed changes you can find here: https://github.com/magento/magento2/pull/29804/files

May be just removing the line "['value_id', 'value']" is enough. The default value for that param is "*". So it's the same result that including all the fields. And it works for community and commerce edition.

Thanks @BavoJanss it worked for me...

Hi @DiegoSana @usman786cs,
Could you add some additional info how we can reproduce this issue?

Could you try to execute following SQL and let us know if there any result?
This SQL checks if you have any product values that not belongs to any product

SELECT COUNT(*)
FROM catalog_product_entity_varchar cpev
LEFT JOIN catalog_product_entity cpe on cpev.entity_id = cpe.entity_id
WHERE cpe.entity_id IS NULL;

For me result is following, and issue isn't reproducing:

mysql> SELECT COUNT(*)
    -> FROM catalog_product_entity_varchar cpev
    -> LEFT JOIN catalog_product_entity cpe on cpev.entity_id = cpe.entity_id
    -> WHERE cpe.entity_id IS NULL;
+----------+
| COUNT(*) |
+----------+
|        0 |
+----------+
1 row in set (0.04 sec)

1) Have a previous Magento (mine is 1.9.3.8) with data, in particular some entries in the url_rewrite table.
2) Run the data-migration-tool to migrate into 2.4.0
3) Run the tool again with --reset (or -r) option.

You should see the issue.

With debugging, it appears that the upgrade script would read the table, do some processing to the records (no changes applied) and then it would try to "insert" using the insertOnDuplicate function which fails if a record is already in the database.

Please my previous update, it details this issue and how to fix it.

Regards
Heider

@engcom-Alfa could you check the following comment? https://github.com/magento/magento2/issues/29365#issuecomment-694178643 Maybe it will help you to identify the issue.

Hi @DiegoSana @usman786cs,
Could you add some additional info how we can reproduce this issue?

Could you try to execute following SQL and let us know if there any result?
This SQL checks if you have any product values that not belongs to any product

SELECT COUNT(*)
FROM catalog_product_entity_varchar cpev
LEFT JOIN catalog_product_entity cpe on cpev.entity_id = cpe.entity_id
WHERE cpe.entity_id IS NULL;

For me result is following, and issue isn't reproducing:

mysql> SELECT COUNT(*)
    -> FROM catalog_product_entity_varchar cpev
    -> LEFT JOIN catalog_product_entity cpe on cpev.entity_id = cpe.entity_id
    -> WHERE cpe.entity_id IS NULL;
+----------+
| COUNT(*) |
+----------+
|        0 |
+----------+
1 row in set (0.04 sec)

@ihor-sviziev i solved this issue. So my database is upgraded succesfully. Any way, in my case the query is with row id.

SELECT COUNT(*) FROM catalog_product_entity_varchar cpev LEFT JOIN catalog_product_entity cpe on cpev.row_id = cpe.row_id WHERE cpe.row_id IS NULL;

Because i use Magento CE.
Before the upgrade, i have some results with this query. So i removed it. Now the result is empty.

Hi @sunel,
Seems like this issue was already fixed in https://github.com/magento/magento2/commit/dd151d11f4d709abb91b82a5d4360aae651c20e3.

Could you confirm that?

@ihor-sviziev Is a tag version that i can try

@sunel there is no version available that contains this fix, but you could apply it as a patch

@ihor-sviziev let me give it a try

Hi @sunel,
The patch already was included into 2.4.1 version, so it will be much easier to test it now. Could you confirm that issue is gone?

Hi @sunel,
As we weren't able to reproduce this issue on 2.4-develop branch and it looks like issue already resolved - I'm closing this issue.

If issue still reproducing - please let us know additional info how to reproduce it.

Hi,
I can reproduce this problem with an update from 2.3.5 to 2.4.1.
So this problem still exists.

I executed the SQL:
SELECT COUNT(*)
FROM catalog_product_entity_varchar cpev
LEFT JOIN catalog_product_entity cpe on cpev.entity_id = cpe.entity_id
WHERE cpe.entity_id IS NULL;

The result is 0

With the pull from @ravi-chandra3197 the upgrade works.
https://github.com/magento/magento2/pull/29804/files

@template-provider couod you add some more info? Do you have it on clean magento installation or some customizations are installed? Are you using magento Open source or ee, b2b?
Unfortunately we still wasn't able to reproduce it

Ok... as it was confirmed that still not fixed - reopening this issue again...

@ihor-sviziev :
Ah sry ... no problem...
Shop Migrated from 1.9.4.5 to 2.3.5 ...
now trying to upgrade from 2.3.5 to 2.4.1
open source for all editions
https://shop.icletta.com

@template-provider ans you're getting exactly the same exception? Or it's a bit different?

Ok, so what I see - your shop is having two languages (store views I believe) and using different urls for different store views for the same category or product. I believe it have to be rechecked with such configuration

@ihor-sviziev :
exactly the same problem ...

Unable to apply data patch Magento\CatalogUrlRewrite\Setup\Patch\Data\UpdateUrlKeyForProducts for module Magento_CatalogUrlRewrite. Original exception message: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`mag`.`catalog_product_entity_varchar`, CONSTRAINT `CAT_PRD_ENTT_VCHR_ENTT_ID_CAT_PRD_ENTT_ENTT_ID` FOREIGN KEY (`entity_id`) REFERENCES `catalog_product_entity` (`entity_id`) ON DELET), query was: INSERT  INTO `catalog_product_entity_varchar` (`value_id`,`value`) VALUES (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?) ON DUPLICATE KEY UPDATE `value` = VALUES(`value`)

@ihor-sviziev :
yes, 2 store views with 2 languages de and en

Hi @engcom-Alfa @engcom-Bravo @engcom-Charlie ,
Could you try to reproduce this issue again with configuring magento in the same way?

  1. Two store views - en & de
  2. Enable showing store code in the URL
  3. Configure different URL keys for categories and for products for the DE & EN versions
  4. Try to upgrade

We had the same issue when upgrading from 2.3.4 to 2.4.1.
As someone else has mentioned, applying this pull request as a patch seemingly works.

I can confirm I'm also having this issue trying to upgrade from magento community 2.3.4 to 2.4.1:

Unable to apply data patch Magento\CatalogUrlRewrite\Setup\Patch\Data\UpdateUrlKeyForProducts for module Magento_CatalogUrlRewrite. Original exception message: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (XXredactedXX.catalog_product_entity_varchar, CONSTRAINTCAT_PRD_ENTT_VCHR_ENTT_ID_CAT_PRD_ENTT_ENTT_IDFOREIGN KEY (entity_id) REFERENCEScatalog_product_entity(entity_id) ON DELET), query was: INSERT INTOcatalog_product_entity_varchar(value_id,value) VALUES (?, ?), (--many snips--) (?, ?) ON DUPLICATE KEY UPDATEvalue= VALUES(value)

I can also confirm that applying the patch from @ravi-chandra3197 allowed the upgrade to proceed. https://github.com/magento/magento2/pull/29804/files

@christianbookpwood any ideas how to reproduce this issue on clean magento installation?

@christianbookpwood any ideas how to reproduce this issue on clean magento installation?

The only thing that comes to mind is that, back when we upgraded to Magento 2.3.3, we had an issue with URL keys, as did a number of other people, described in this issue: https://github.com/magento/magento2/issues/26499 -- it was still an issue when we upgraded to 2.3.4, which is the version we're currently on. We're now trying to upgrade from 2.3.4 to 2.4.1.

We had applied the fix specified by that issue reporter to our version of vendor/magento/module-catalog-url-rewrite/Model/ProductUrlPathGenerator.php, and thereafter our url keys were properly updated. We had to reapply this fix when we upgraded from 2.3.3 to 2.3.4.

These modules both seem to deal with Url keys, so I'm wondering if our previous fix to the ProductUrlPathGenerator.php file put our system into a state that is causing the issue with UpdateUrlKeyForProducts.php.

Was this page helpful?
0 / 5 - 0 ratings