cancel
Showing results for 
Search instead for 
Did you mean: 

Integrity constraint violation: 1062 Duplicate entry - catalog_product_entity_tier_price

Integrity constraint violation: 1062 Duplicate entry - catalog_product_entity_tier_price

Hello,

we have Magento 2.4.1 version, updating some existing products with bulk REST API call:

rest/async/bulk/V1/products/bySku
Sometimes it happens that the processing of these calls ends with status 3 "Unique constraint violation found", with the following details:

 

## 2022-02-11 12:19:51
## 1027050 ## QUERY
SQL: INSERT INTO `catalog_product_entity_tier_price` (`entity_id`, `all_groups`, `customer_group_id`, `qty`, `value`, `website_id`, `percentage_value`) VALUES (?, ?, ?, ?, ?, ?, ?)
BIND: array (
  0 => 2134292,
  1 => 0,
  2 => 4,
  3 => 1.0,
  4 => 9.22,
  5 => 0,
  6 => NULL,
)
TIME: 0.0002

## 2022-02-11 12:19:51
EXCEPTION 
PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '2134292-0-4-1.0000-0' for key 'UNQ_E8AB433B9ACB00343ABB312AD2FAB087' in /opt/magento-2.4.1-2/apps/magento/htdocs/vendor/magento/framework/DB/Statement/Pdo/Mysql.php:91

Obviously the records are already present.
Why does Magento try to insert them again on the same entity id?

Stack trace:

#0 /opt/magento-2.4.1-2/apps/magento/htdocs/vendor/magento/framework/DB/Statement/Pdo/Mysql.php(91): PDOStatement->execute(Array)
#1 /opt/magento-2.4.1-2/apps/magento/htdocs/vendor/magento/framework/DB/Statement/Pdo/Mysql.php(107): Magento\Framework\DB\Statement\Pdo\Mysql->Magento\Framework\DB\Statement\Pdo\{closure}()
#2 /opt/magento-2.4.1-2/apps/magento/htdocs/vendor/magento/framework/DB/Statement/Pdo/Mysql.php(92): Magento\Framework\DB\Statement\Pdo\Mysql->tryExecute(Object(Closure))
#3 /opt/magento-2.4.1-2/apps/magento/htdocs/vendor/magento/zendframework1/library/Zend/Db/Statement.php(303): Magento\Framework\DB\Statement\Pdo\Mysql->_execute(Array)
#4 /opt/magento-2.4.1-2/apps/magento/htdocs/vendor/magento/zendframework1/library/Zend/Db/Adapter/Abstract.php(480): Zend_Db_Statement->execute(Array)
#5 /opt/magento-2.4.1-2/apps/magento/htdocs/vendor/magento/zendframework1/library/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query('INSERT INTO `ca...', Array)
#6 /opt/magento-2.4.1-2/apps/magento/htdocs/vendor/magento/framework/DB/Adapter/Pdo/Mysql.php(558): Zend_Db_Adapter_Pdo_Abstract->query('INSERT INTO `ca...', Array)
#7 /opt/magento-2.4.1-2/apps/magento/htdocs/vendor/magento/framework/DB/Adapter/Pdo/Mysql.php(625): Magento\Framework\DB\Adapter\Pdo\Mysql->_query('INSERT INTO `ca...', Array)
#8 /opt/magento-2.4.1-2/apps/magento/htdocs/generated/code/Magento/Framework/DB/Adapter/Pdo/Mysql/Interceptor.php(95): Magento\Framework\DB\Adapter\Pdo\Mysql->query('INSERT INTO `ca...', Array)
#9 /opt/magento-2.4.1-2/apps/magento/htdocs/vendor/magento/zendframework1/library/Zend/Db/Adapter/Abstract.php(576): Magento\Framework\DB\Adapter\Pdo\Mysql\Interceptor->query('INSERT INTO `ca...', Array)
#10 /opt/magento-2.4.1-2/apps/magento/htdocs/generated/code/Magento/Framework/DB/Adapter/Pdo/Mysql/Interceptor.php(1049): Zend_Db_Adapter_Abstract->insert('catalog_product...', Array)
#11 /opt/magento-2.4.1-2/apps/magento/htdocs/vendor/magento/module-catalog/Model/ResourceModel/Product/Attribute/Backend/GroupPrice/AbstractGroupPrice.php(138): Magento\Framework\DB\Adapter\Pdo\Mysql\Interceptor->insert('catalog_product...', Array)
#12 /opt/magento-2.4.1-2/apps/magento/htdocs/vendor/magento/module-catalog/Model/Product/Attribute/Backend/TierPrice/UpdateHandler.php(168): Magento\Catalog\Model\ResourceModel\Product\Attribute\Backend\GroupPrice\AbstractGroupPrice->savePriceData(Object(Magento\Framework\DataObject))
#13 /opt/magento-2.4.1-2/apps/magento/htdocs/vendor/magento/module-catalog/Model/Product/Attribute/Backend/TierPrice/UpdateHandler.php(109): Magento\Catalog\Model\Product\Attribute\Backend\TierPrice\UpdateHandler->insertValues(2134292, Array)
#14 /opt/magento-2.4.1-2/apps/magento/htdocs/vendor/magento/framework/EntityManager/Operation/Update/UpdateExtensions.php(49): Magento\Catalog\Model\Product\Attribute\Backend\TierPrice\UpdateHandler->execute(Object(Magento\Catalog\Model\Product\Interceptor), Array)
#15 /opt/magento-2.4.1-2/apps/magento/htdocs/vendor/magento/framework/EntityManager/Operation/Update.php(109): Magento\Framework\EntityManager\Operation\Update\UpdateExtensions->execute(Object(Magento\Catalog\Model\Product\Interceptor), Array)
#16 /opt/magento-2.4.1-2/apps/magento/htdocs/vendor/magento/framework/EntityManager/EntityManager.php(96): Magento\Framework\EntityManager\Operation\Update->execute(Object(Magento\Catalog\Model\Product\Interceptor), Array)
#17 /opt/magento-2.4.1-2/apps/magento/htdocs/vendor/magento/module-catalog/Model/ResourceModel/Product.php(758): Magento\Framework\EntityManager\EntityManager->save(Object(Magento\Catalog\Model\Product\Interceptor))
#18 /opt/magento-2.4.1-2/apps/magento/htdocs/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Catalog\Model\ResourceModel\Product->save(Object(Magento\Catalog\Model\Product\Interceptor))
#19 /opt/magento-2.4.1-2/apps/magento/htdocs/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Catalog\Model\ResourceModel\Product\Interceptor->___callParent('save', Array)
#20 /opt/magento-2.4.1-2/apps/magento/htdocs/vendor/magento/module-catalog-search/Model/Indexer/Fulltext/Plugin/Product.php(58): Magento\Catalog\Model\ResourceModel\Product\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Catalog\Model\Product\Interceptor))
#21 /opt/magento-2.4.1-2/apps/magento/htdocs/vendor/magento/module-catalog-search/Model/Indexer/Fulltext/Plugin/Product.php(28): Magento\CatalogSearch\Model\Indexer\Fulltext\Plugin\Product->addCommitCallback(Object(Magento\Catalog\Model\ResourceModel\Product\Interceptor), Object(Closure), Object(Magento\Catalog\Model\Product\Interceptor))
#22 /opt/magento-2.4.1-2/apps/magento/htdocs/vendor/magento/framework/Interception/Interceptor.php(135): Magento\CatalogSearch\Model\Indexer\Fulltext\Plugin\Product->aroundSave(Object(Magento\Catalog\Model\ResourceModel\Product\Interceptor), Object(Closure), Object(Magento\Catalog\Model\Product\Interceptor))
#23 /opt/magento-2.4.1-2/apps/magento/htdocs/vendor/magento/framework/App/Cache/FlushCacheByTags.php(69): Magento\Catalog\Model\ResourceModel\Product\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Catalog\Model\Product\Interceptor))
#24 /opt/magento-2.4.1-2/apps/magento/htdocs/vendor/magento/framework/Interception/Interceptor.php(135): Magento\Framework\App\Cache\FlushCacheByTags->aroundSave(Object(Magento\Catalog\Model\ResourceModel\Product\Interceptor), Object(Closure), Object(Magento\Catalog\Model\Product\Interceptor))
#25 /opt/magento-2.4.1-2/apps/magento/htdocs/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Catalog\Model\ResourceModel\Product\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Catalog\Model\Product\Interceptor))
#26 /opt/magento-2.4.1-2/apps/magento/htdocs/generated/code/Magento/Catalog/Model/ResourceModel/Product/Interceptor.php(194): Magento\Catalog\Model\ResourceModel\Product\Interceptor->___callPlugins('save', Array, Array)
#27 /opt/magento-2.4.1-2/apps/magento/htdocs/vendor/magento/module-catalog/Model/ProductRepository.php(819): Magento\Catalog\Model\ResourceModel\Product\Interceptor->save(Object(Magento\Catalog\Model\Product\Interceptor))
#28 /opt/magento-2.4.1-2/apps/magento/htdocs/vendor/magento/module-catalog/Model/ProductRepository.php(569): Magento\Catalog\Model\ProductRepository->saveProduct(Object(Magento\Catalog\Model\Product\Interceptor))
#29 /opt/magento-2.4.1-2/apps/magento/htdocs/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Catalog\Model\ProductRepository->save(Object(Magento\Catalog\Model\Product\Interceptor))
#30 /opt/magento-2.4.1-2/apps/magento/htdocs/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Catalog\Model\ProductRepository\Interceptor->___callParent('save', Array)
#31 /opt/magento-2.4.1-2/apps/magento/htdocs/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Catalog\Model\ProductRepository\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Catalog\Model\Product\Interceptor))
#32 /opt/magento-2.4.1-2/apps/magento/htdocs/generated/code/Magento/Catalog/Model/ProductRepository/Interceptor.php(41): Magento\Catalog\Model\ProductRepository\Interceptor->___callPlugins('save', Array, Array)
#33 [internal function]: Magento\Catalog\Model\ProductRepository\Interceptor->save(Object(Magento\Catalog\Model\Product\Interceptor))
#34 /opt/magento-2.4.1-2/apps/magento/htdocs/vendor/magento/module-asynchronous-operations/Model/OperationProcessor.php(193): call_user_func_array(Array, Array)
#35 /opt/magento-2.4.1-2/apps/magento/htdocs/vendor/magento/module-asynchronous-operations/Model/OperationProcessor.php(136): Magento\AsynchronousOperations\Model\OperationProcessor->executeHandler(Array, Array)
#36 /opt/magento-2.4.1-2/apps/magento/htdocs/vendor/magento/module-asynchronous-operations/Model/MassConsumerEnvelopeCallback.php(103): Magento\AsynchronousOperations\Model\OperationProcessor->process('{"id":3,"bulk_u...')
#37 /opt/magento-2.4.1-2/apps/magento/htdocs/vendor/magento/framework/Interception/Interceptor.php(58): Magento\AsynchronousOperations\Model\MassConsumerEnvelopeCallback->execute(Object(Magento\Framework\MessageQueue\Envelope))
#38 /opt/magento-2.4.1-2/apps/magento/htdocs/vendor/magento/framework/Interception/Interceptor.php(138): Magento\AsynchronousOperations\Model\MassConsumerEnvelopeCallback\Interceptor->___callParent('execute', Array)
#39 /opt/magento-2.4.1-2/apps/magento/htdocs/vendor/magento/module-amqp-store/Plugin/AsynchronousOperations/MassConsumerEnvelopeCallback.php(96): Magento\AsynchronousOperations\Model\MassConsumerEnvelopeCallback\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\MessageQueue\Envelope))
#40 /opt/magento-2.4.1-2/apps/magento/htdocs/vendor/magento/framework/Interception/Interceptor.php(135): Magento\AmqpStore\Plugin\AsynchronousOperations\MassConsumerEnvelopeCallback->aroundExecute(Object(Magento\AsynchronousOperations\Model\MassConsumerEnvelopeCallback\Interceptor), Object(Closure), Object(Magento\Framework\MessageQueue\Envelope))
#41 /opt/magento-2.4.1-2/apps/magento/htdocs/vendor/magento/framework/Interception/Interceptor.php(153): Magento\AsynchronousOperations\Model\MassConsumerEnvelopeCallback\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\MessageQueue\Envelope))
#42 /opt/magento-2.4.1-2/apps/magento/htdocs/generated/code/Magento/AsynchronousOperations/Model/MassConsumerEnvelopeCallback/Interceptor.php(23): Magento\AsynchronousOperations\Model\MassConsumerEnvelopeCallback\Interceptor->___callPlugins('execute', Array, NULL)
#43 /opt/magento-2.4.1-2/apps/magento/htdocs/vendor/magento/module-asynchronous-operations/Model/MassConsumer.php(105): Magento\AsynchronousOperations\Model\MassConsumerEnvelopeCallback\Interceptor->execute(Object(Magento\Framework\MessageQueue\Envelope))
#44 /opt/magento-2.4.1-2/apps/magento/htdocs/vendor/magento/framework-message-queue/CallbackInvoker.php(95): Magento\AsynchronousOperations\Model\MassConsumer->Magento\AsynchronousOperations\Model\{closure}(Object(Magento\Framework\MessageQueue\Envelope))
#45 /opt/magento-2.4.1-2/apps/magento/htdocs/vendor/magento/module-asynchronous-operations/Model/MassConsumer.php(79): Magento\Framework\MessageQueue\CallbackInvoker->invoke(Object(Magento\Framework\Amqp\Queue), '10000', Object(Closure), 9223372036854775807, 1)
#46 /opt/magento-2.4.1-2/apps/magento/htdocs/vendor/magento/module-message-queue/Console/StartConsumerCommand.php(90): Magento\AsynchronousOperations\Model\MassConsumer->process('10000')
#47 /opt/magento-2.4.1-2/apps/magento/htdocs/vendor/symfony/console/Command/Command.php(255): Magento\MessageQueue\Console\StartConsumerCommand->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#48 /opt/magento-2.4.1-2/apps/magento/htdocs/vendor/magento/framework/Interception/Interceptor.php(58): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#49 /opt/magento-2.4.1-2/apps/magento/htdocs/vendor/magento/framework/Interception/Interceptor.php(138): Magento\MessageQueue\Console\StartConsumerCommand\Interceptor->___callParent('run', Array)
#50 /opt/magento-2.4.1-2/apps/magento/htdocs/vendor/magento/framework/Interception/Interceptor.php(153): Magento\MessageQueue\Console\StartConsumerCommand\Interceptor->Magento\Framework\Interception\{closure}(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#51 /opt/magento-2.4.1-2/apps/magento/htdocs/generated/code/Magento/MessageQueue/Console/StartConsumerCommand/Interceptor.php(77): Magento\MessageQueue\Console\StartConsumerCommand\Interceptor->___callPlugins('run', Array, Array)
#52 /opt/magento-2.4.1-2/apps/magento/htdocs/generated/code/Magento/MessageQueue/Console/StartConsumerCommand/Proxy.php(143): Magento\MessageQueue\Console\StartConsumerCommand\Interceptor->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#53 /opt/magento-2.4.1-2/apps/magento/htdocs/vendor/symfony/console/Application.php(1009): Magento\MessageQueue\Console\StartConsumerCommand\Proxy->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#54 /opt/magento-2.4.1-2/apps/magento/htdocs/vendor/symfony/console/Application.php(273): Symfony\Component\Console\Application->doRunCommand(Object(Magento\MessageQueue\Console\StartConsumerCommand\Proxy), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#55 /opt/magento-2.4.1-2/apps/magento/htdocs/vendor/magento/framework/Console/Cli.php(115): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#56 /opt/magento-2.4.1-2/apps/magento/htdocs/vendor/symfony/console/Application.php(149): Magento\Framework\Console\Cli->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#57 /opt/magento-2.4.1-2/apps/magento/htdocs/bin/magento(30): Symfony\Component\Console\Application->run()
#58 {main}

Thanks.