Skip to content

Duplicated & missing product rows in system product export #4531

@wbyrnetx

Description

@wbyrnetx

Steps to reproduce

  1. Install Magento from 2.0.2 tag (the one we tested on, but likely affects all versions).
  2. Create/import enough products so that when running an export, the main product query will have to use offsets to batch the results
  3. Look at the CSV and you will find duplicated product entries and some products that are missing altogether. From my testing, the total count is always correct and matches a SELECT COUN(*) FROM catalog_product_entity.

I spent some time looking into what may be causing this, and I believe it has to do with the ORDER BY has_options clause in the MySQL query. What I'm not sure about, is why the Magento export orders by that field in the first place.

When combining that ORDER BY with an OFFSET, the MySQL result order is inconsistent.

This can be observed by running the following queries against the Magento2 sample database.

  1. Query the first 10 products
    SELECT entity_id, sku FROM catalog_product_entity AS e ORDER BY e.has_options ASC LIMIT 10;

  2. Query the first 20 products
    SELECT entity_id, sku FROM catalog_product_entity AS e ORDER BY e.has_options ASC LIMIT 20;

If you compare the result set... you'll see what I'm talking about. For me, the first row in query 1 has entity_id 9347. In query 2, the first row has entity_id 90. Once you introduce offsetting the results, you get the same problem.

My proposed solution would be to order by entity_id in the export query, as that will always produce consistent result ordering, even with limits and offsets. This would require a change in Magento\CatalogImportExport\Model\Export\Product:: export

However, without knowing why it's sorted by has_options in the first place, I can't be sure.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions