I have a magento 2.4.7-p3 instance and I faced a strange bug.
Here is how I reproduce it.
1- Add something to the cart, as a guest and not logged in
2- In checkout/cart click on Paypal button, in the pop up log in to your Paypal. Click on “Continue to review the order” button and go to the paypal review page(paypal/express/review/)
3- Don’t place the order instead login to your customer account in Magento (I have already some products in the cart with my account)
4- Go to checkout/cart page and try to check out again using paypal (from the checkout/cart page). By pressing “Continue to review the order” button, you will received the following error:
No such entity with cartId = 123456789
I edited theNoSuchEntityException.php class to get some more info and added some logger inside __construct as below:
public function __construct(Phrase $phrase = null, Exception $cause = null, $code = 0)
{
$logFile = '/var/www/html/var/log/fpc.log';
// Custom file logging
file_put_contents(
$logFile,
date('Y-m-d H:i:s') . ' | ' . __CLASS__ . ' | ' . __FUNCTION__ . ' | ' . __LINE__ . ' | Initializing NoSuchEntityException' . PHP_EOL,
FILE_APPEND
);
// Log exception phrase
file_put_contents(
$logFile,
date('Y-m-d H:i:s') . ' | ' . __CLASS__ . ' | ' . __FUNCTION__ . ' | ' . __LINE__ . ' | Phrase: ' . print_r($phrase, true) . PHP_EOL,
FILE_APPEND
);
// Log exception cause
file_put_contents(
$logFile,
date('Y-m-d H:i:s') . ' | ' . __CLASS__ . ' | ' . __FUNCTION__ . ' | ' . __LINE__ . ' | Cause: ' . print_r($cause, true) . PHP_EOL,
FILE_APPEND
);
// Log exception code
file_put_contents(
$logFile,
date('Y-m-d H:i:s') . ' | ' . __CLASS__ . ' | ' . __FUNCTION__ . ' | ' . __LINE__ . ' | Code: ' . print_r($code, true) . PHP_EOL,
FILE_APPEND
);
// Log backtrace
$backtrace = debug_backtrace();
foreach ($backtrace as $index => $_stack) {
$fileInfo = $_stack['file'] ?? 'undefined';
$lineInfo = $_stack['line'] ?? 'undefined';
file_put_contents(
$logFile,
date('Y-m-d H:i:s') . " | Backtrace $index | File: $fileInfo | Line: $lineInfo" . PHP_EOL,
FILE_APPEND
);
}
if ($phrase === null) {
$phrase = new Phrase('No such entity.');
}
parent::__construct($phrase, $cause, $code);
}
and here is the output logs
2025-01-20 13:28:42 | MagentoFrameworkExceptionNoSuchEntityException | __construct | 40 | Initializing NoSuchEntityException
2025-01-20 13:28:42 | MagentoFrameworkExceptionNoSuchEntityException | __construct | 47 | Phrase: MagentoFrameworkPhrase Object
(
[text:MagentoFrameworkPhrase:private] => No such entity with %fieldName = %fieldValue
[arguments:MagentoFrameworkPhrase:private] => Array
(
[fieldName] => cartId
[fieldValue] => 123456789
)
)
2025-01-20 13:28:42 | MagentoFrameworkExceptionNoSuchEntityException | __construct | 54 | Cause:
2025-01-20 13:28:42 | MagentoFrameworkExceptionNoSuchEntityException | __construct | 61 | Code: 0
2025-01-20 13:28:42 | Backtrace 0 | File: /var/www/html/vendor/magento/framework/Exception/NoSuchEntityException.php | Line: 93
2025-01-20 13:28:42 | Backtrace 1 | File: /var/www/html/vendor/magento/module-quote/Model/QuoteRepository.php | Line: 250
2025-01-20 13:28:42 | Backtrace 2 | File: /var/www/html/vendor/magento/module-quote/Model/QuoteRepository.php | Line: 149
2025-01-20 13:28:42 | Backtrace 3 | File: /var/www/html/vendor/magento/framework/Interception/Interceptor.php | Line: 58
2025-01-20 13:28:42 | Backtrace 4 | File: /var/www/html/vendor/magento/framework/Interception/Interceptor.php | Line: 138
2025-01-20 13:28:42 | Backtrace 5 | File: /var/www/html/vendor/magento/framework/Interception/Interceptor.php | Line: 153
2025-01-20 13:28:42 | Backtrace 6 | File: /var/www/html/generated/code/Magento/Quote/Model/QuoteRepository/Interceptor.php | Line: 23
2025-01-20 13:28:42 | Backtrace 7 | File: /var/www/html/vendor/magento/module-paypal/Controller/Express/AbstractExpress.php | Line: 247
2025-01-20 13:28:42 | Backtrace 8 | File: /var/www/html/vendor/magento/module-paypal/Controller/Express/OnAuthorization.php | Line: 123
2025-01-20 13:28:42 | Backtrace 9 | File: /var/www/html/vendor/magento/framework/Interception/Interceptor.php | Line: 58
2025-01-20 13:28:42 | Backtrace 10 | File: /var/www/html/vendor/magento/framework/Interception/Interceptor.php | Line: 138
2025-01-20 13:28:42 | Backtrace 11 | File: /var/www/html/vendor/magento/framework/Interception/Interceptor.php | Line: 153
2025-01-20 13:28:42 | Backtrace 12 | File: /var/www/html/generated/code/Magento/Paypal/Controller/Express/OnAuthorization/Interceptor.php | Line: 23
2025-01-20 13:28:42 | Backtrace 13 | File: /var/www/html/vendor/magento/framework/App/Action/Action.php | Line: 111
2025-01-20 13:28:42 | Backtrace 14 | File: /var/www/html/vendor/magento/framework/Interception/Interceptor.php | Line: 58
2025-01-20 13:28:42 | Backtrace 15 | File: /var/www/html/vendor/magento/framework/Interception/Interceptor.php | Line: 138
2025-01-20 13:28:42 | Backtrace 16 | File: /var/www/html/vendor/magento/framework/Interception/Interceptor.php | Line: 153
2025-01-20 13:28:42 | Backtrace 17 | File: /var/www/html/generated/code/Magento/Paypal/Controller/Express/OnAuthorization/Interceptor.php | Line: 77
2025-01-20 13:28:42 | Backtrace 18 | File: /var/www/html/vendor/magento/framework/App/FrontController.php | Line: 245
2025-01-20 13:28:42 | Backtrace 19 | File: /var/www/html/vendor/magento/framework/App/FrontController.php | Line: 212
2025-01-20 13:28:42 | Backtrace 20 | File: /var/www/html/vendor/magento/framework/App/FrontController.php | Line: 146
2025-01-20 13:28:42 | Backtrace 21 | File: /var/www/html/vendor/magento/framework/Interception/Interceptor.php | Line: 58
2025-01-20 13:28:42 | Backtrace 22 | File: /var/www/html/vendor/magento/framework/Interception/Interceptor.php | Line: 138
2025-01-20 13:28:42 | Backtrace 23 | File: /var/www/html/vendor/magento/module-store/App/FrontController/Plugin/RequestPreprocessor.php | Line: 99
2025-01-20 13:28:42 | Backtrace 24 | File: /var/www/html/vendor/magento/framework/Interception/Interceptor.php | Line: 135
2025-01-20 13:28:42 | Backtrace 25 | File: /var/www/html/vendor/amasty/aminvisiblecaptcha/Plugin/Framework/App/FrontControllerInterface/ValidateCaptcha.php | Line: 124
2025-01-20 13:28:42 | Backtrace 26 | File: /var/www/html/vendor/magento/framework/Interception/Interceptor.php | Line: 135
2025-01-20 13:28:42 | Backtrace 27 | File: /var/www/html/vendor/magento/module-page-cache/Model/App/FrontController/BuiltinPlugin.php | Line: 72
2025-01-20 13:28:42 | Backtrace 28 | File: /var/www/html/vendor/magento/framework/Interception/Interceptor.php | Line: 135
2025-01-20 13:28:42 | Backtrace 29 | File: /var/www/html/vendor/magento/framework/Interception/Interceptor.php | Line: 153
2025-01-20 13:28:42 | Backtrace 30 | File: /var/www/html/generated/code/Magento/Framework/App/FrontController/Interceptor.php | Line: 23
2025-01-20 13:28:42 | Backtrace 31 | File: /var/www/html/vendor/magento/framework/App/Http.php | Line: 116
2025-01-20 13:28:42 | Backtrace 32 | File: /var/www/html/vendor/magento/framework/Interception/Interceptor.php | Line: 58
2025-01-20 13:28:42 | Backtrace 33 | File: /var/www/html/vendor/magento/framework/Interception/Interceptor.php | Line: 138
2025-01-20 13:28:42 | Backtrace 34 | File: /var/www/html/vendor/magento/module-application-performance-monitor/Plugin/ApplicationPerformanceMonitor.php | Line: 38
2025-01-20 13:28:42 | Backtrace 35 | File: /var/www/html/vendor/magento/framework/Interception/Interceptor.php | Line: 135
2025-01-20 13:28:42 | Backtrace 36 | File: /var/www/html/vendor/magento/framework/Interception/Interceptor.php | Line: 153
2025-01-20 13:28:42 | Backtrace 37 | File: /var/www/html/generated/code/Magento/Framework/App/Http/Interceptor.php | Line: 23
2025-01-20 13:28:42 | Backtrace 38 | File: /var/www/html/vendor/magento/framework/App/Bootstrap.php | Line: 264
I noticed as well that the cartId doesn’t exist in database.I think Magento has an issue with merging guest quote and customer quote via Papal Express.
I have tested this on another project as well and I was able to reproduce it. I think it’s an issue with Magento and not 3rd party modules.
Could someone please tell me how I can fix this issue?