-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
ProductRepository sku cache is corrupted when cacheLimit is reached #11537
Conversation
Nummeric SKUs are renumbered when array_slice is used to purge parts of the products-by-sku cache array. Per php documentation: > Note that array_slice() will reorder and reset the numeric array indices by default. as `$this->instances` has the SKUs as keys, the resulting shortened array might contain indexes that now point to a wrong product.
Ideally, this pull request should be backported to 2.2, as we were hit pretty hard by this bug during daily product imports for one of our larger 2.2 shop instance. |
ah ok, sorry. should I recreate a new pull request for 2.2-develop or can you move it?
it is not throwing an error but silently returning wrong cache entries if you're "lucky" enough. in our case, we had >1000 articles loaded with high numeric SKUs (like '123456'). then an article with a low numeric SKU ( |
Let's just process this one into
Yeah, I understand this, just there are two |
@heldchen thanks for your contribution! You can now do a backport into |
as I'm not familiar with the magento github workflow and don't want to cause trouble: with backport you mean a cherry pick of 3d6f738 into |
absolutely right. |
#11553 - I hope I did everything correctly, if not, I'd appreciate some pointers to avoid the overhead for future PRs. cheers |
Haha i just wanted to fix it now, we have a shop with all numeric skus ;> thank you @heldchen |
Numeric SKUs are renumbered when array_slice is used to purge parts of the products-by-sku cache array. Per php documentation:
PHP considers numeric-looking values like
'123'
as numeric even when used as array indices. so although the$product->getSku()
returns a string, the string might still look like a number and is then renumbered duringarray_slice
.as
$this->instances
has the SKUs as keys, the resulting shortened array might contain indexes that now point to a wrong product, which can lead to the ProductRespository returning the wrong product for a given SKU.Description
Manual testing scenarios
load >1000 products by sku, where the skus are numeric via
$productRepository->get($sku);
, then observe the$productRepository->instance
arrayContribution checklist