Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Magento 2.4 Upgrade issue Unable to apply data patch Magento\CatalogUrlRewrite\Setup\Patch\Data\UpdateUrlKeyForProducts #29365

Closed
1 of 5 tasks
sunel opened this issue Aug 3, 2020 · 51 comments · Fixed by #29804
Assignees
Labels
Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Priority: P1 Once P0 defects have been fixed, a defect having this priority is the next candidate for fixing. Progress: done Reported on 2.3.4 Indicates original Magento version for the Issue report. Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Severity: S1 Affects critical data or functionality and forces users to employ a workaround.

Comments

@sunel
Copy link

sunel commented Aug 3, 2020

Preconditions (*)

  1. Magento 2.4.0
  2. Magento 2.4-develop

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.

  • 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”.
@m2-assistant
Copy link

m2-assistant bot commented Aug 3, 2020

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


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

🕙 You can find the schedule on the Magento Community Calendar page.

📞 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.

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

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

@magento-engcom-team magento-engcom-team added the Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed label Aug 3, 2020
@pmclain
Copy link
Contributor

pmclain commented Aug 4, 2020

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

@dharake
Copy link

dharake commented Aug 5, 2020

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

@dharake
Copy link

dharake commented Aug 5, 2020

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

@MichaelThessel
Copy link

Can confirm issue. Upgrading from 2.3.5 to 2.4.

@moni921
Copy link

moni921 commented Aug 6, 2020

Any solution, we are stuck here

@sunel
Copy link
Author

sunel commented Aug 6, 2020

@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)');
...

@vanvasten
Copy link

vanvasten commented Aug 6, 2020

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

@BavoJanss
Copy link

BavoJanss commented Aug 7, 2020

For the update to succeed all keys should be included in the query.
Change lines according below in Magento\CatalogUrlRewrite\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')

@dharake
Copy link

dharake commented Aug 7, 2020

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?

@vanvasten
Copy link

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

@dharake
Copy link

dharake commented Aug 7, 2020

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

@hostep
Copy link
Contributor

hostep commented Aug 7, 2020

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 🙂

@dverkade
Copy link
Member

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.

@HeiderSati
Copy link

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

@ghost ghost added the Priority: P1 Once P0 defects have been fixed, a defect having this priority is the next candidate for fixing. label Aug 31, 2020
@luka4
Copy link

luka4 commented Sep 9, 2020

For the update to succeed all keys should be included in the query.
Change lines according below in Magento\CatalogUrlRewrite\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']

@ghost ghost unassigned ravi-chandra3197 Sep 11, 2020
@ihor-sviziev
Copy link
Contributor

ihor-sviziev commented Oct 28, 2020

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

@paul-blundell
Copy link

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.

@magento-engcom-team magento-engcom-team added the Reported on 2.3.4 Indicates original Magento version for the Issue report. label Nov 13, 2020
@christianbookpwood
Copy link

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, 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 (?, ?), (--many snips--) (?, ?) ON DUPLICATE KEY UPDATE value = VALUES(value)

@christianbookpwood
Copy link

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

@ihor-sviziev
Copy link
Contributor

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

@christianbookpwood
Copy link

@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: #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.

@thomas-kl1
Copy link
Member

I got that issue too, trying to upgrade 2.2 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 (mpbio_qa.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 C), query was: INSERT INTO catalog_product_entity_varchar (value_id,value) VALUES (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?) ON DUPLICATE KEY UPDATE value = VALUES(value)

@thomas-kl1
Copy link
Member

For the update to succeed all keys should be included in the query.
Change lines according below in Magento\CatalogUrlRewrite\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')

this seems to fix it

@engcom-Alfa engcom-Alfa added Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed labels Feb 1, 2021
@magento-engcom-team
Copy link
Contributor

✅ Confirmed by @engcom-Alfa
Thank you for verifying the issue. Based on the provided information internal tickets MC-40700 were created

Issue Available: @engcom-Alfa, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

@thanura
Copy link

thanura commented Mar 10, 2021

Upgrading from 2.3.6-p1 to 2.4.2. Still got the same issue. I have created the patch using the commit here : https://github.com/ravi-chandra3197/magento2/tree/patch-29365

` diff --git a/vendor/magento/module-catalog-url-rewrite/Setup/Patch/Data/UpdateUrlKeyForProducts.php b/vendor/magento/module-catalog-url-rewrite/Setup/Patch/Data/UpdateUrlKeyForProducts.php
index 5e70399129..f74d8ca358 100644
--- a/vendor/magento/module-catalog-url-rewrite/Setup/Patch/Data/UpdateUrlKeyForProducts.php
+++ b/vendor/magento/module-catalog-url-rewrite/Setup/Patch/Data/UpdateUrlKeyForProducts.php
@@ -34,19 +34,27 @@ class UpdateUrlKeyForProducts implements DataPatchInterface, PatchVersionInterfa
*/
private $urlProduct;

    +    /**
    +     * @var \Magento\Framework\EntityManager\MetadataPool
    +     */
    +    private $metadataPool;
    +
         /**
          * @param ModuleDataSetupInterface $moduleDataSetup
          * @param EavSetupFactory $eavSetupFactory
          * @param Url $urlProduct
    +     * @param \Magento\Framework\EntityManager\MetadataPool $metadataPool
          */
         public function __construct(
             ModuleDataSetupInterface $moduleDataSetup,
             EavSetupFactory $eavSetupFactory,
    -        Url $urlProduct
    +        Url $urlProduct,
    +        \Magento\Framework\EntityManager\MetadataPool $metadataPool
         ) {
             $this->moduleDataSetup = $moduleDataSetup;
             $this->eavSetup = $eavSetupFactory->create(['setup' => $moduleDataSetup]);
             $this->urlProduct = $urlProduct;
    +        $this->metadataPool = $metadataPool;
         }
     
         /**
    @@ -58,7 +66,7 @@ class UpdateUrlKeyForProducts implements DataPatchInterface, PatchVersionInterfa
             $table = $this->moduleDataSetup->getTable('catalog_product_entity_varchar');
             $select = $this->moduleDataSetup->getConnection()->select()->from(
                 $table,
    -            ['value_id', 'value']
    +            [$this->getProductLinkField(), 'attribute_id', 'store_id', 'value_id', 'value']
             )->where(
                 'attribute_id = ?',
                 $this->eavSetup->getAttributeId($productTypeId, 'url_key')
    @@ -99,4 +107,17 @@ class UpdateUrlKeyForProducts implements DataPatchInterface, PatchVersionInterfa
         {
             return [];
         }
    +
    +    /**
    +     * Return product id field name - entity_id|row_id
    +     *
    +     * @return string
    +     * @throws \Exception
    +     */
    +    private function getProductLinkField()
    +    {
    +        return $this->metadataPool
    +            ->getMetadata(\Magento\Catalog\Api\Data\ProductInterface::class)
    +            ->getLinkField();
    +    }
     }`

@barbazul
Copy link
Contributor

I just noticed this fix is in the main branch but wasn't released in 2.4.2-p1 which is dissapointing

@ihor-sviziev
Copy link
Contributor

ihor-sviziev commented May 12, 2021

@barbazul 2.4.2-p1 is a security-only release. That's why this change wasn't added

@roman204
Copy link

roman204 commented Jul 7, 2021

For anyone who needs a ready-to-use patch file for composer patches:
here you go ->>> save it as patch file and configure it for composer patches, viola

Index: Setup/Patch/Data/UpdateUrlKeyForProducts.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/Setup/Patch/Data/UpdateUrlKeyForProducts.php b/Setup/Patch/Data/UpdateUrlKeyForProducts.php
--- a/Setup/Patch/Data/UpdateUrlKeyForProducts.php	(date 1625672707821)
+++ b/Setup/Patch/Data/UpdateUrlKeyForProducts.php	(date 1625672707821)
@@ -34,6 +34,11 @@
      */
     private $urlProduct;
 
+    /**
+     * @var \Magento\Framework\EntityManager\MetadataPool
+     */
+    private $metadataPool;
+
     /**
      * @param ModuleDataSetupInterface $moduleDataSetup
      * @param EavSetupFactory $eavSetupFactory
@@ -42,11 +47,13 @@
     public function __construct(
         ModuleDataSetupInterface $moduleDataSetup,
         EavSetupFactory $eavSetupFactory,
-        Url $urlProduct
+        Url $urlProduct,
+        \Magento\Framework\EntityManager\MetadataPool $metadataPool
     ) {
         $this->moduleDataSetup = $moduleDataSetup;
         $this->eavSetup = $eavSetupFactory->create(['setup' => $moduleDataSetup]);
         $this->urlProduct = $urlProduct;
+        $this->metadataPool = $metadataPool;
     }
 
     /**
@@ -58,7 +65,7 @@
         $table = $this->moduleDataSetup->getTable('catalog_product_entity_varchar');
         $select = $this->moduleDataSetup->getConnection()->select()->from(
             $table,
-            ['value_id', 'value']
+            [$this->getProductLinkField(), 'attribute_id', 'store_id', 'value_id', 'value']
         )->where(
             'attribute_id = ?',
             $this->eavSetup->getAttributeId($productTypeId, 'url_key')
@@ -99,4 +106,17 @@
     {
         return [];
     }
+
+    /**
+     * Return product id field name - entity_id|row_id
+     *
+     * @return string
+     * @throws \Exception
+     */
+    private function getProductLinkField()
+    {
+        return $this->metadataPool
+            ->getMetadata(\Magento\Catalog\Api\Data\ProductInterface::class)
+            ->getLinkField();
+    }
 }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Priority: P1 Once P0 defects have been fixed, a defect having this priority is the next candidate for fixing. Progress: done Reported on 2.3.4 Indicates original Magento version for the Issue report. Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Severity: S1 Affects critical data or functionality and forces users to employ a workaround.
Projects
Archived in project