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

Integrity constraint violation in elasticsuite_tracker_log_customer_link #2390

Closed
paugnu opened this issue Dec 14, 2021 · 14 comments
Closed
Assignees
Labels

Comments

@paugnu
Copy link

paugnu commented Dec 14, 2021

Preconditions

Magento Version : Open Source 2.4.2
ElasticSuite Version : 2.10.8.1
Environment : Production

Steps to reproduce

  1. Search any string
  2. 500 error page is thrown

This happens to some users, it seems to be related to session issues.

Expected result

  1. Search results page should be displayed

Actual result

  1. 500 error page is thrown

Log shows:
{"0":"SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`xxxxx`.`elasticsuite_tracker_log_customer_link`, CONSTRAINT `ELASTICSUITE_TRACKER_LOG_CSTR_LNK_CSTR_ID_CSTR_ENTT_ENTT_ID` FOREIGN KEY (`customer_id`) REFERENCES `customer_entity` (`entity_i), query was: INSERT INTO `elasticsuite_tracker_log_customer_link` (`customer_id`,`session_id`,`visitor_id`) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE `customer_id` = VALUES(`customer_id`), `session_id` = VALUES(`session_id`), `visitor_id` = VALUES(`visitor_id`)","1":"#1 Magento\\Framework\\DB\\Statement\\Pdo\\Mysql->_execute() called at [vendor\/magento\/zendframework1\/library\/Zend\/Db\/Statement.php:303]\n#2 Zend_Db_Statement->execute() called at [vendor\/magento\/zendframework1\/library\/Zend\/Db\/Adapter\/Abstract.php:480]\n#3 Zend_Db_Adapter_Abstract->query() called at [vendor\/magento\/zendframework1\/library\/Zend\/Db\/Adapter\/Pdo\/Abstract.php:238]\n#4 Zend_Db_Adapter_Pdo_Abstract->query() called at [vendor\/magento\/framework\/DB\/Adapter\/Pdo\/Mysql.php:560]\n#5 Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql->_query() called at [vendor\/magento\/framework\/DB\/Adapter\/Pdo\/Mysql.php:627]\n#6 Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql->query() called at [generated\/code\/Magento\/Framework\/DB\/Adapter\/Pdo\/Mysql\/Interceptor.php:95]\n#7 Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql\\Interceptor->query() called at [vendor\/magento\/framework\/DB\/Adapter\/Pdo\/Mysql.php:2031]\n#8 Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql->insertOnDuplicate() called at [generated\/code\/Magento\/Framework\/DB\/Adapter\/Pdo\/Mysql\/Interceptor.php:374]\n#9 Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql\\Interceptor->insertOnDuplicate() called at [vendor\/smile\/elasticsuite\/src\/module-elasticsuite-tracker\/Model\/ResourceModel\/CustomerLink.php:42]\n#10 Smile\\ElasticsuiteTracker\\Model\\ResourceModel\\CustomerLink->saveLink() called at [vendor\/smile\/elasticsuite\/src\/module-elasticsuite-tracker\/Model\/Customer\/TrackingService.php:143]\n#11 Smile\\ElasticsuiteTracker\\Model\\Customer\\TrackingService->addCustomerLink() called at [vendor\/smile\/elasticsuite\/src\/module-elasticsuite-tracker\/Model\/Customer\/TrackingService.php:80]\n#12 Smile\\ElasticsuiteTracker\\Model\\Customer\\TrackingService->addEvent() called at [vendor\/smile\/elasticsuite\/src\/module-elasticsuite-tracker\/Observer\/TrackRedirectIfOneResult.php:129]\n#13 Smile\\ElasticsuiteTracker\\Observer\\TrackRedirectIfOneResult->logEvent() called at [vendor\/smile\/elasticsuite\/src\/module-elasticsuite-tracker\/Observer\/TrackRedirectIfOneResult.php:96]\n#14 Smile\\ElasticsuiteTracker\\Observer\\TrackRedirectIfOneResult->execute() called at [vendor\/magento\/framework\/Event\/Invoker\/InvokerDefault.php:88]\n#15 Magento\\Framework\\Event\\Invoker\\InvokerDefault->_callObserverMethod() called at [vendor\/magento\/framework\/Event\/Invoker\/InvokerDefault.php:74]\n#16 Magento\\Framework\\Event\\Invoker\\InvokerDefault->dispatch() called at [vendor\/magento\/framework\/Event\/Manager.php:66]\n#17 Magento\\Framework\\Event\\Manager->dispatch() called at [generated\/code\/Magento\/Framework\/Event\/Manager\/Proxy.php:95]\n#18 Magento\\Framework\\Event\\Manager\\Proxy->dispatch() called at [vendor\/smile\/elasticsuite\/src\/module-elasticsuite-catalog\/Plugin\/CatalogSearch\/ResultPlugin.php:131]\n#19 Smile\\ElasticsuiteCatalog\\Plugin\\CatalogSearch\\ResultPlugin->aroundExecute() called at [vendor\/magento\/framework\/Interception\/Interceptor.php:135]\n#20 Magento\\CatalogSearch\\Controller\\Result\\Index\\Interceptor->Magento\\Framework\\Interception\\{closure}() called at [vendor\/magento\/framework\/App\/Action\/Plugin\/ActionFlagNoDispatchPlugin.php:51]\n#21 Magento\\Framework\\App\\Action\\Plugin\\ActionFlagNoDispatchPlugin->aroundExecute() called at [vendor\/magento\/framework\/Interception\/Interceptor.php:135]\n#22 Magento\\CatalogSearch\\Controller\\Result\\Index\\Interceptor->Magento\\Framework\\Interception\\{closure}() called at [vendor\/magento\/framework\/Interception\/Interceptor.php:153]\n#23 Magento\\CatalogSearch\\Controller\\Result\\Index\\Interceptor->___callPlugins() called at [generated\/code\/Magento\/CatalogSearch\/Controller\/Result\/Index\/Interceptor.php:23]\n#24 Magento\\CatalogSearch\\Controller\\Result\\Index\\Interceptor->execute() called at [vendor\/magento\/framework\/App\/Action\/Action.php:111]\n#25 Magento\\Framework\\App\\Action\\Action->dispatch() called at [vendor\/magento\/framework\/Interception\/Interceptor.php:58]\n#26 Magento\\CatalogSearch\\Controller\\Result\\Index\\Interceptor->___callParent() called at [vendor\/magento\/framework\/Interception\/Interceptor.php:138]\n#27 Magento\\CatalogSearch\\Controller\\Result\\Index\\Interceptor->Magento\\Framework\\Interception\\{closure}() called at [vendor\/magento\/framework\/Interception\/Interceptor.php:153]\n#28 Magento\\CatalogSearch\\Controller\\Result\\Index\\Interceptor->___callPlugins() called at [generated\/code\/Magento\/CatalogSearch\/Controller\/Result\/Index\/Interceptor.php:32]\n#29 Magento\\CatalogSearch\\Controller\\Result\\Index\\Interceptor->dispatch() called at [vendor\/magento\/framework\/App\/FrontController.php:186]\n#30 Magento\\Framework\\App\\FrontController->processRequest() called at [vendor\/magento\/framework\/App\/FrontController.php:118]\n#31 Magento\\Framework\\App\\FrontController->dispatch() called at [vendor\/magento\/framework\/Interception\/Interceptor.php:58]\n#32 Magento\\Framework\\App\\FrontController\\Interceptor->___callParent() called at [vendor\/magento\/framework\/Interception\/Interceptor.php:138]\n#33 Magento\\Framework\\App\\FrontController\\Interceptor->Magento\\Framework\\Interception\\{closure}() called at [vendor\/magento\/module-store\/App\/FrontController\/Plugin\/RequestPreprocessor.php:99]\n#34 Magento\\Store\\App\\FrontController\\Plugin\\RequestPreprocessor->aroundDispatch() called at [vendor\/magento\/framework\/Interception\/Interceptor.php:135]\n#35 Magento\\Framework\\App\\FrontController\\Interceptor->Magento\\Framework\\Interception\\{closure}() called at [app\/code\/Amasty\/InvisibleCaptcha\/Plugin\/Framework\/App\/FrontControllerInterface\/ValidateCaptcha.php:124]\n#36 Amasty\\InvisibleCaptcha\\Plugin\\Framework\\App\\FrontControllerInterface\\ValidateCaptcha->aroundDispatch() called at [vendor\/magento\/framework\/Interception\/Interceptor.php:135]\n#37 Magento\\Framework\\App\\FrontController\\Interceptor->Magento\\Framework\\Interception\\{closure}() called at [vendor\/magento\/module-page-cache\/Model\/App\/FrontController\/BuiltinPlugin.php:71]\n#38 Magento\\PageCache\\Model\\App\\FrontController\\BuiltinPlugin->aroundDispatch() called at [vendor\/magento\/framework\/Interception\/Interceptor.php:135]\n#39 Magento\\Framework\\App\\FrontController\\Interceptor->Magento\\Framework\\Interception\\{closure}() called at [vendor\/magento\/framework\/Interception\/Interceptor.php:153]\n#40 Magento\\Framework\\App\\FrontController\\Interceptor->___callPlugins() called at [generated\/code\/Magento\/Framework\/App\/FrontController\/Interceptor.php:23]\n#41 Magento\\Framework\\App\\FrontController\\Interceptor->dispatch() called at [vendor\/magento\/framework\/App\/Http.php:116]\n#42 Magento\\Framework\\App\\Http->launch() called at [generated\/code\/Magento\/Framework\/App\/Http\/Interceptor.php:23]\n#43 Magento\\Framework\\App\\Http\\Interceptor->launch() called at [vendor\/magento\/framework\/App\/Bootstrap.php:263]\n#44 Magento\\Framework\\App\\Bootstrap->run() called at [pub\/index.php:29]\n","url":"\/es\/catalogsearch\/result\/?q=036432","script_name":"\/index.php","report_id":"757635743ef0598dc6d08138d65f6150d5475ae37c10a3123a4ec75be04bc1b9"}

The error seems to be related to the user session. This only happens to backoffice users that manage different user sessions in the same browser window (usually is customer service).

I've added a try/catch statement in the file module-elasticsuite-tracker/Model/ResourceModel/CustomerLink.php, and that was enough to solve it. But... is it the correct way?

@vahonc
Copy link
Collaborator

vahonc commented Dec 16, 2021

Hello @paugnu,

Have you used some third-party module for log in as a customer from Magento BO? It's free or paid module?
Maybe in their something not properly works with user sessions or could be linked with cookies or smth like that.

BR,
Vadym

@paugnu
Copy link
Author

paugnu commented Dec 16, 2021

Hi @vahonc

We're using the Magento Native login as customer functionality:
https://github.com/magento/magento2/tree/2.4-develop/app/code/Magento/LoginAsCustomer

@romainruaud
Copy link
Collaborator

@vahonc can you try to reproduce this one with using the "loginascustomer" and try to propose a fix ?

@vahonc
Copy link
Collaborator

vahonc commented Jan 5, 2022

Ok, I will take on it.

@vahonc
Copy link
Collaborator

vahonc commented Jan 6, 2022

@paugnu,

Could you show what Login as Customer settings are in your project like on my screenshot below:

Screenshot from 2022-01-06 15-43-38

Perhaps, you smth change here.

Also, please provide a scenario of what exactly do your back-office users/customer service when they use login as a customer feature. This will help us take a closer look at this problem.

BR,
Vadym

@romainruaud
Copy link
Collaborator

If you are not able to reproduce, probably a try catch around this line will be fine : https://github.com/Smile-SA/elasticsuite/blob/2.10.x/src/module-elasticsuite-tracker/Observer/TrackRedirectIfOneResult.php#L129

vahonc added a commit to vahonc/elasticsuite that referenced this issue Jan 10, 2022
@vahonc
Copy link
Collaborator

vahonc commented Jan 10, 2022

I was not able to reproduce this issue. However, as we decided with a team I've added a try/catch statement at a more proper place.

BR,
Vadym

@paugnu
Copy link
Author

paugnu commented Jan 10, 2022

@paugnu,

Could you show what Login as Customer settings are in your project like on my screenshot below:

Screenshot from 2022-01-06 15-43-38

Perhaps, you smth change here.

Also, please provide a scenario of what exactly do your back-office users/customer service when they use login as a customer feature. This will help us take a closer look at this problem.

BR, Vadym

Hi @vahonc

Here is my configuration:

image

@vahonc
Copy link
Collaborator

vahonc commented Jan 10, 2022

Hi @paugnu,

It seems the Login as Customer settings is the same one my and your screenshots.

Could you please test my fixes on your environment and tell me if you will notice any issues. But don't forget to remove try/catch statement which you added in the file module-elasticsuite-tracker/Model/ResourceModel/CustomerLink.php.

BR,
Vadym

@paugnu
Copy link
Author

paugnu commented Jan 10, 2022

Hi @vahonc

I will:

  • Remove the try/catch I added
  • I'll check the logs this week to note the number of times this issue is logged (given that I cannot reproduce it myself)
  • I'll apply the changes you proposed and check another week to see if the issue disappears

(I do this in order to be sure the fix is correct). I'll keep you updated.

@paugnu
Copy link
Author

paugnu commented Jan 26, 2022

Hi @vahonc

I just wanted to let you know that your fix didn't solve the issue. So far, the only thing that solves the issue is adding the try/catch to the file module-elasticsuite-tracker/Model/ResourceModel/CustomerLink.php as I mentioned in the issue description.

@vahonc
Copy link
Collaborator

vahonc commented Jan 28, 2022

Hello @paugnu,

Could you clarify in which line you added try/catch statement to the file module-elasticsuite-tracker/Model/ResourceModel/CustomerLink.php?

BR,
Vadym

@paugnu
Copy link
Author

paugnu commented Jan 28, 2022

@vahonc
Copy link
Collaborator

vahonc commented Jan 28, 2022

Since I was unable to reproduce this issue I will update my PR with your solution. Thanks.

BR,
Vadym

vahonc added a commit to vahonc/elasticsuite that referenced this issue Jan 28, 2022
romainruaud added a commit that referenced this issue Feb 11, 2022
…ion-2.10-fix

Fixes #2390, added a try/catch statement for logEvent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants