From 321baf009cdd6958e031dd79b0253af5b4fd3bbc Mon Sep 17 00:00:00 2001 From: kapilvus Date: Mon, 15 Jun 2026 21:39:33 +0530 Subject: [PATCH 1/3] fix: catch NoSuchEntityException in InvalidSkuProcessor for bundle products productRepository->get($sku) in retrieveInvalidSkuList() had no exception handling for the case where a bundle product is deleted between the initial retrieveProductIdsBySkus() lookup and the repository fetch. This caused an uncaught NoSuchEntityException to propagate up and fail the entire batch when using POST /V1/products/base-prices with bundle products. Apply the same try/catch pattern used in ACP2E-4998 (TierPriceValidator): catch NoSuchEntityException and treat the SKU as invalid so the rest of the batch continues processing. Fixes #40882 --- .../Price/Validation/InvalidSkuProcessor.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Catalog/Model/Product/Price/Validation/InvalidSkuProcessor.php b/app/code/Magento/Catalog/Model/Product/Price/Validation/InvalidSkuProcessor.php index d44ea38a34d31..0e00f68b4d961 100644 --- a/app/code/Magento/Catalog/Model/Product/Price/Validation/InvalidSkuProcessor.php +++ b/app/code/Magento/Catalog/Model/Product/Price/Validation/InvalidSkuProcessor.php @@ -6,6 +6,8 @@ namespace Magento\Catalog\Model\Product\Price\Validation; +use Magento\Framework\Exception\NoSuchEntityException; + /** * Class is responsible to detect list of invalid SKU values from list of provided skus and allowed product types. */ @@ -57,9 +59,18 @@ public function retrieveInvalidSkuList(array $skus, array $allowedProductTypes, if ($allowedPriceTypeValue && $type == \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE - && $this->productRepository->get($sku)->getPriceType() != $allowedPriceTypeValue ) { - $valueTypeIsAllowed = true; + try { + $product = $this->productRepository->get($sku); + if ($product->getPriceType() != $allowedPriceTypeValue) { + $valueTypeIsAllowed = true; + } + } catch (NoSuchEntityException $e) { + // Product was deleted between the ID lookup and repository fetch. + // Treat as invalid SKU so the rest of the batch continues. + $skuDiff[] = $sku; + break; + } } if (!in_array($type, $allowedProductTypes) || $valueTypeIsAllowed) { From 6e315bf19e5cd0086cfd284970b4762644fde108 Mon Sep 17 00:00:00 2001 From: kapil971390 Date: Tue, 16 Jun 2026 11:42:56 +0530 Subject: [PATCH 2/3] chore: re-trigger CLA check From eb592e269275e12b61c7eeb4e348961b0ebca001 Mon Sep 17 00:00:00 2001 From: kapil971390 Date: Tue, 17 Nov 2026 22:56:15 +0530 Subject: [PATCH 3/3] test: cover NoSuchEntityException handling in InvalidSkuProcessor --- .../Validation/InvalidSkuProcessorTest.php | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/app/code/Magento/Catalog/Test/Unit/Model/Product/Price/Validation/InvalidSkuProcessorTest.php b/app/code/Magento/Catalog/Test/Unit/Model/Product/Price/Validation/InvalidSkuProcessorTest.php index 0c16957466d07..124f2c6048130 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/Product/Price/Validation/InvalidSkuProcessorTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/Product/Price/Validation/InvalidSkuProcessorTest.php @@ -13,6 +13,7 @@ use Magento\Catalog\Model\Product\Price\Validation\InvalidSkuProcessor; use Magento\Catalog\Model\Product\Type; use Magento\Catalog\Model\ProductIdLocatorInterface; +use Magento\Framework\Exception\NoSuchEntityException; use Magento\Framework\TestFramework\Unit\Helper\MockCreationTrait; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; use PHPUnit\Framework\MockObject\MockObject; @@ -98,4 +99,73 @@ public function testRetrieveInvalidSkuList() $this->invalidSkuProcessor->retrieveInvalidSkuList($skus, $allowedProductTypes, $allowedPriceTypeValue) ); } + + /** + * A bundle product can be deleted between the retrieveProductIdsBySkus() lookup and the + * productRepository->get() call a few lines later. Before this fix, the resulting + * NoSuchEntityException propagated uncaught and failed the whole batch instead of just + * this one SKU. + * + * @return void + */ + public function testRetrieveInvalidSkuListWhenBundleProductDeletedConcurrently() + { + $deletedSku = 'DELETED-BUNDLE-SKU'; + $idsBySku = [$deletedSku => [235235235 => Type::TYPE_BUNDLE]]; + $this->productIdLocator->expects($this->atLeastOnce())->method('retrieveProductIdsBySkus') + ->willReturn($idsBySku); + $this->productRepository->expects($this->atLeastOnce())->method('get') + ->willThrowException(new NoSuchEntityException()); + + // array_values(): retrieveInvalidSkuList() never guarantees zero-based + // keys (array_udiff()'s internal next-index counter isn't reset just + // because the filtered result is empty) and no caller relies on the + // keys, only the values -- same as filterSkuList()'s own array_diff(). + $this->assertEquals( + [$deletedSku], + array_values($this->invalidSkuProcessor->retrieveInvalidSkuList( + [$deletedSku], + [Type::TYPE_BUNDLE], + true + )) + ); + } + + /** + * One bundle product being deleted mid-batch must not stop the rest of the batch from + * being processed normally. + * + * @return void + */ + public function testRetrieveInvalidSkuListContinuesBatchWhenOneBundleProductIsDeletedConcurrently() + { + $deletedSku = 'DELETED-BUNDLE-SKU'; + $validSku = 'VALID-BUNDLE-SKU'; + $idsBySku = [ + $deletedSku => [235235235 => Type::TYPE_BUNDLE], + $validSku => [235235236 => Type::TYPE_BUNDLE], + ]; + $this->productIdLocator->expects($this->atLeastOnce())->method('retrieveProductIdsBySkus') + ->willReturn($idsBySku); + + $validProduct = $this->createPartialMockWithReflection(Product::class, ['getPriceType']); + $validProduct->method('getPriceType')->willReturn(true); + + $this->productRepository->method('get') + ->willReturnCallback(function ($sku) use ($deletedSku, $validProduct) { + if ($sku === $deletedSku) { + throw new NoSuchEntityException(); + } + return $validProduct; + }); + + $this->assertEquals( + [$deletedSku], + array_values($this->invalidSkuProcessor->retrieveInvalidSkuList( + [$deletedSku, $validSku], + [Type::TYPE_BUNDLE], + true + )) + ); + } }