Skip to content

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'xxx.html-0' for key 'URL_REWRITE_REQUEST_PATH_STORE_ID #22

Open
@wagnert

Description

@wagnert

Describe the bug
During product import the exception PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'braga-de-talle-alto-grazia-3.html-15' for key 'URL_REWRITE_REQUEST_PATH_STORE_ID' in /Users/wagnert/Workspace_Idea/techdivision/import-cli-simple/vendor/techdivision/import/src/Actions/Processors/AbstractBaseProcessor.php:220 will be thrown

To Reproduce
Steps to reproduce the issue:

  1. Magento 2.3.5/2.4.0 Instanz, either Community orCommerce, is available in directory <magento-install-dir>
  2. The import base directory has been created with mkdir <magento-install-dir>/var/importexport
  3. The master branch has been cloned with git clone [email protected]:techdivision/import-cli-simple.git into the directory <import-cli-simple-dir>
  4. The dependencies has been installed with cd <import-cli-simple-dir> && composer install
  5. Change back to the Magento install directory by entering the command cd <magento-install-dir>
  6. Extract the ZIP archive with the three CSV files with the command unzip import-product-url-rewrite.zip var/tmp
  7. Run the first import by invoking the command cp <magento-install-dir>/var/tmp/product-import_20201009-161909_01.csv var/importexport && import-simple import:create:ok-file && import-simple import:products which should result in a DB state
    import_first_run
  8. Run the second import by invoking the command cp <magento-install-dir>/var/tmp/product-import_20201009-161909_02.csv var/importexport && import-simple import:create:ok-file && import-simple import:products which should result in a DB state
    import_second_run
  9. Run the third import by invoking the command cp <magento-install-dir>/var/tmp/product-import_20201009-161909_03.csv var/importexport && import-simple import:create:ok-file && import-simple import:products which will fail with the exception
    exception_stack and should result in the DB state
    import_third_run

Artefacts

Expected behavior
The expected result has to be defined.

Additional context
The problem results out of the following facts:

  1. The first import creates a product with the SKU 24-MB01 and the URL key joust-duffle-bag and creates an URL rewrite therefore
  2. The second import updates the URL key to joust-duffle-bag-s because the product name changes and creates a 301 redirect for joust-duffle-bag to joust-duffle-bag-s
  3. The third import creates a new product with the SKU 24-MB02 that uses the old URL key joust-duffle-bag (because it'll be created from the name) but fails when the importer tries to create the URL rewrites because an URL rewrite with the request_path: 'joust-duffle-bag' and store_id: 0 already exists as 301 for the product of SKU 24-MB01

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions