Nosto/nosto-magento2

SQLSTATE[23000]: Integrity constraint violation

calin-ImDigital opened this issue · 2 comments

Magento 2 version(s) used: 2.3.4
Extension version(s) affected: 4.0.4

Description
I can see some exceptions on the latest version dure some unique key for "nosto_tagging_product_cache" table

Next Magento\Framework\DB\Adapter\DuplicateException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '21853-1' for key 'NOSTO_TAGGING_PRODUCT_CACHE_PRODUCT_ID_STORE_ID', query was: INSERT INTO `nosto_tagging_product_cache` (`product_id`, `store_id`, `in_sync`, `is_dirty`, `created_at`, `updated_at`) VALUES (?, ?, ?, ?, '2020-02-24 08:33:28', '2020-02-24 08:33:28') in /srv/releases/20200224102800/vendor/magento/framework/DB/Adapter/Pdo/Mysql.php:585
Stack trace:
#0 /srv/releases/20200224102800/vendor/magento/framework/DB/Adapter/Pdo/Mysql.php(613): Magento\Framework\DB\Adapter\Pdo\Mysql->_query('INSERT INTO `no...', Array)
#1 /srv/releases/20200224102800/vendor/magento/zendframework1/library/Zend/Db/Adapter/Abstract.php(576): Magento\Framework\DB\Adapter\Pdo\Mysql->query('INSERT INTO `no...', Array)
#2 /srv/releases/20200224102800/vendor/magento/framework/Model/ResourceModel/Db/AbstractDb.php(781): Zend_Db_Adapter_Abstract->insert('nosto_tagging_p...', Array)
#3 /srv/releases/20200224102800/vendor/magento/framework/Model/ResourceModel/Db/AbstractDb.php(421): Magento\Framework\Model\ResourceModel\Db\AbstractDb->saveNewObject(Object(Nosto\Tagging\Model\Product\Cache))
#4 /srv/releases/20200224102800/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Framework\Model\ResourceModel\Db\AbstractDb->save(Object(Nosto\Tagging\Model\Product\Cache))
#5 /srv/releases/20200224102800/vendor/magento/framework/Interception/Interceptor.php(138): Nosto\Tagging\Model\ResourceModel\Product\Cache\Interceptor->___callParent('save', Array)
#6 /srv/releases/20200224102800/vendor/nosto/module-nostotagging/Plugin/ProductData.php(99): Nosto\Tagging\Model\ResourceModel\Product\Cache\Interceptor->Magento\Framework\Interception\{closure}(Object(Nosto\Tagging\Model\Product\Cache))
#7 /srv/releases/20200224102800/vendor/magento/framework/Interception/Interceptor.php(135): Nosto\Tagging\Plugin\ProductData->aroundSave(Object(Nosto\Tagging\Model\ResourceModel\Product\Cache\Interceptor), Object(Closure), Object(Nosto\Tagging\Model\Product\Cache))
#8 /srv/releases/20200224102800/vendor/magento/framework/Interception/Interceptor.php(153): Nosto\Tagging\Model\ResourceModel\Product\Cache\Interceptor->Magento\Framework\Interception\{closure}(Object(Nosto\Tagging\Model\Product\Cache))
#9 /srv/releases/20200224102800/generated/code/Nosto/Tagging/Model/ResourceModel/Product/Cache/Interceptor.php(26): Nosto\Tagging\Model\ResourceModel\Product\Cache\Interceptor->___callPlugins('save', Array, NULL)
#10 /srv/releases/20200224102800/vendor/nosto/module-nostotagging/Model/Product/Cache/CacheRepository.php(205): Nosto\Tagging\Model\ResourceModel\Product\Cache\Interceptor->save(Object(Nosto\Tagging\Model\Product\Cache))
#11 /srv/releases/20200224102800/vendor/nosto/module-nostotagging/Model/Service/Cache/CacheService.php(304): Nosto\Tagging\Model\Product\Cache\CacheRepository->save(Object(Nosto\Tagging\Model\Product\Cache))
#12 /srv/releases/20200224102800/vendor/nosto/module-nostotagging/Model/Service/Product/CachingProductService.php(96): Nosto\Tagging\Model\Service\Cache\CacheService->updateOrCreateDirtyEntity(Object(Magento\Catalog\Model\Product\Interceptor), Object(Magento\Store\Model\Store\Interceptor))
#13 /srv/releases/20200224102800/vendor/nosto/module-nostotagging/Model/Service/Product/SanitizingProductService.php(73): Nosto\Tagging\Model\Service\Product\CachingProductService->getProduct(Object(Magento\Catalog\Model\Product\Interceptor), Object(Magento\Store\Model\Store\Interceptor))
#14 /srv/releases/20200224102800/vendor/nosto/module-nostotagging/Block/Product.php(141): Nosto\Tagging\Model\Service\Product\SanitizingProductService->getProduct(Object(Magento\Catalog\Model\Product\Interceptor), Object(Magento\Store\Model\Store\Interceptor))
#15 /srv/releases/20200224102800/vendor/nosto/module-nostotagging/Block/TaggingTrait.php(71): Nosto\Tagging\Block\Product->getAbstractObject()
#16 /srv/releases/20200224102800/vendor/magento/framework/View/Element/AbstractBlock.php(1099): Nosto\Tagging\Block\Product->_toHtml()
#17 /srv/releases/20200224102800/vendor/magento/framework/View/Element/AbstractBlock.php(1103): Magento\Framework\View\Element\AbstractBlock->Magento\Framework\View\Element\{closure}()
#18 /srv/releases/20200224102800/vendor/magento/framework/View/Element/AbstractBlock.php(673): Magento\Framework\View\Element\AbstractBlock->_loadCache()
#19 /srv/releases/20200224102800/vendor/magento/framework/View/Layout.php(564): Magento\Framework\View\Element\AbstractBlock->toHtml()
#20 /srv/releases/20200224102800/vendor/magento/framework/View/Layout.php(540): Magento\Framework\View\Layout->_renderBlock('nosto.product')
#21 /srv/releases/20200224102800/vendor/magento/framework/View/Layout.php(495): Magento\Framework\View\Layout->renderNonCachedElement('nosto.product')
#22 /srv/releases/20200224102800/vendor/magento/framework/View/Layout.php(592): Magento\Framework\View\Layout->renderElement('nosto.product', false)
#23 /srv/releases/20200224102800/vendor/magento/framework/View/Layout.php(542): Magento\Framework\View\Layout->_renderContainer('content', false)
#24 /srv/releases/20200224102800/vendor/magento/framework/View/Layout.php(495): Magento\Framework\View\Layout->renderNonCachedElement('content')
#25 /srv/releases/20200224102800/vendor/magento/framework/View/Layout.php(592): Magento\Framework\View\Layout->renderElement('content', false)
#26 /srv/releases/20200224102800/vendor/magento/framework/View/Layout.php(542): Magento\Framework\View\Layout->_renderContainer('main', false)
#27 /srv/releases/20200224102800/vendor/magento/framework/View/Layout.php(495): Magento\Framework\View\Layout->renderNonCachedElement('main')
#28 /srv/releases/20200224102800/vendor/magento/framework/View/Layout.php(592): Magento\Framework\View\Layout->renderElement('main', false)
#29 /srv/releases/20200224102800/vendor/magento/framework/View/Layout.php(542): Magento\Framework\View\Layout->_renderContainer('columns', false)
#30 /srv/releases/20200224102800/vendor/magento/framework/View/Layout.php(495): Magento\Framework\View\Layout->renderNonCachedElement('columns')
#31 /srv/releases/20200224102800/vendor/magento/framework/View/Layout.php(592): Magento\Framework\View\Layout->renderElement('columns', false)
#32 /srv/releases/20200224102800/vendor/magento/framework/View/Layout.php(542): Magento\Framework\View\Layout->_renderContainer('main.content', false)
#33 /srv/releases/20200224102800/vendor/magento/framework/View/Layout.php(495): Magento\Framework\View\Layout->renderNonCachedElement('main.content')
#34 /srv/releases/20200224102800/vendor/magento/framework/View/Layout.php(592): Magento\Framework\View\Layout->renderElement('main.content', false)
#35 /srv/releases/20200224102800/vendor/magento/framework/View/Layout.php(542): Magento\Framework\View\Layout->_renderContainer('page.wrapper', false)
#36 /srv/releases/20200224102800/vendor/magento/framework/View/Layout.php(495): Magento\Framework\View\Layout->renderNonCachedElement('page.wrapper')
#37 /srv/releases/20200224102800/vendor/magento/framework/View/Layout.php(592): Magento\Framework\View\Layout->renderElement('page.wrapper', false)
#38 /srv/releases/20200224102800/vendor/magento/framework/View/Layout.php(542): Magento\Framework\View\Layout->_renderContainer('root', false)
#39 /srv/releases/20200224102800/vendor/magento/framework/View/Layout.php(495): Magento\Framework\View\Layout->renderNonCachedElement('root')
#40 /srv/releases/20200224102800/vendor/magento/framework/View/Layout.php(961): Magento\Framework\View\Layout->renderElement('root')
#41 /srv/releases/20200224102800/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Framework\View\Layout->getOutput()
#42 /srv/releases/20200224102800/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Framework\View\Layout\Interceptor->___callParent('getOutput', Array)
#43 /srv/releases/20200224102800/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Framework\View\Layout\Interceptor->Magento\Framework\Interception\{closure}()
#44 
Next Magento\Framework\Exception\AlreadyExistsException: Unique constraint violation found in /srv/releases/20200224102800/vendor/magento/framework/Model/ResourceModel/Db/AbstractDb.php:431

How to reproduce
Browse category and product pages will be enough to generate the errror above

Magento 2 mode

  • Developer
  • [X ] Production

Full page cache

  • [X ] Enabled
  • Disabled

Nosto indexer mode

  • Update On Save
  • [X ] Update By Schedule

Thanks for reporting this one as well @cdiacon-img. I could not however reproduce this. Could you check what do you have in nosto_tagging_product_cache table for this specific product and store id? Meaning that is the product_data column empty for that product_id and store_id. It seems that the cached product is null here https://github.com/Nosto/nosto-magento2/blob/develop/Model/Service/Cache/CacheService.php#L297-L304 or for some reason Magento doesn't treat the object as existing one.

@hannunosto
That is strange I cannot replicate anymore, I checked the file you mention and indeed it should create only cached product does not exist anymore. I'll close the issue and will let you know if I see it again. Thanks.