Strange duplicate error
-
12-01-2021 - |
Question
I have solve a quite weird problem:
Frontend (product category or search results)
Item (Magento\Downloadable\Model\Link) with the same ID "1240" already exists.
(with a huge error stack)
(Once I figured out which products caused the error):
Backend, product page:
Warning: Illegal string offset 'is_in_stock' in vendor/magento/module-catalog-inventory/Ui/DataProvider/Product/Form/Modifier/AdvancedInventory.php on line 87
Having check downloadable_link table, which has a unique index on link_id, there was no duplicates.
In this case, reindexing causes no error and solves nothing.
Solution
But... the products causing the above mentionned errors had multiple empty downloadable_links.
To find out which lines are redundant (inspiration from magento2-blog.com)
SELECT * FROM downloadable_link
WHERE product_id in (
SELECT product_id
FROM downloadable_link
GROUP BY product_id
HAVING ( COUNT(product_id) > 1 )
)
Spot the lines having NULL as values, extract from my sql dump:
INSERT INTO `downloadable_link` (`link_id`, `product_id`, `sort_order`, `number_of_downloads`, `is_shareable`, `link_url`, `link_file`, `link_type`, `sample_url`, `sample_file`, `sample_type`) VALUES
[...]
(1239, 1302, 0, 0, 0, NULL, '', 'file', NULL, NULL, NULL),
(1240, 1302, 0, 0, 0, NULL, '', 'file', NULL, NULL, NULL),
[...]
(1454, 1515, 0, 0, 0, NULL, '', 'file', NULL, NULL, NULL),
(1455, 1515, 0, 0, 0, NULL, '', 'file', NULL, NULL, NULL),
[...]
Removing the lines having link_id 1240
and 1455
solved the problem.
My best guess is that these useless-redundant-offensive lines have been generated during products import.