magento / adobe-stock-integration

Magento Adobe Stock integration Community Project.
Open Software License 3.0
60 stars 92 forks source link

Error when saving image from stock that does not have Category #1846

Closed sivaschenko closed 4 years ago

sivaschenko commented 4 years ago

Steps to reproduce (*)

  1. Open Adobe Stock Panel from Media Gallery
  2. Search for "Distant deer in a misty forest"
  3. In the search results find an image with category "None"
  4. Save Preview

image

Expected result (*)

Image is saved successfully, no errors appear

Actual result (*)

Image is saved but an error appears "An error occurred during adobe stock asset save."

Error in the exception log:

report.CRITICAL: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`main`.`adobe_stock_asset`, CONSTRAINT `ADOBE_STOCK_ASSET_CATEGORY_ID_ADOBE_STOCK_CATEGORY_ID` FOREIGN KEY (`category_id`) REFERENCES `adobe_stock_category` (`id`) ON DELETE SET NULL), query was: INSERT  INTO `adobe_stock_asset` (`id`,`media_gallery_id`,`category_id`,`creator_id`,`is_licensed`,`creation_date`) VALUES (?, ?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE `id` = VALUES(`id`), `media_gallery_id` = VALUES(`media_gallery_id`), `category_id` = VALUES(`category_id`), `creator_id` = VALUES(`creator_id`), `is_licensed` = VALUES(`is_licensed`), `creation_date` = VALUES(`creation_date`) {"exception":"[object] (Zend_Db_Statement_Exception(code: 23000): SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`main`.`adobe_stock_asset`, CONSTRAINT `ADOBE_STOCK_ASSET_CATEGORY_ID_ADOBE_STOCK_CATEGORY_ID` FOREIGN KEY (`category_id`) REFERENCES `adobe_stock_category` (`id`) ON DELETE SET NULL), query was: INSERT  INTO `adobe_stock_asset` (`id`,`media_gallery_id`,`category_id`,`creator_id`,`is_licensed`,`creation_date`) VALUES (?, ?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE `id` = VALUES(`id`), `media_gallery_id` = VALUES(`media_gallery_id`), `category_id` = VALUES(`category_id`), `creator_id` = VALUES(`creator_id`), `is_licensed` = VALUES(`is_licensed`), `creation_date` = VALUES(`creation_date`) at /app/vendor/magento/framework/DB/Statement/Pdo/Mysql.php:110, PDOException(code: 23000): SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`main`.`adobe_stock_asset`, CONSTRAINT `ADOBE_STOCK_ASSET_CATEGORY_ID_ADOBE_STOCK_CATEGORY_ID` FOREIGN KEY (`category_id`) REFERENCES `adobe_stock_category` (`id`) ON DELETE SET NULL) at /app/vendor/magento/framework/DB/Statement/Pdo/Mysql.php:91)"} []

Proposed solution (backward compatible)

In case Category is empty - we should load/create "None" category and use it for the asset

m2-assistant[bot] commented 4 years ago

Hi @sivaschenko. Thank you for your report. To help us process this issue please make sure that you provided sufficient information.

Please, add a comment to assign the issue: @magento I am working on this


okorshenko commented 4 years ago

Please check on the previous version of ASI. We need to understand if this is a regression issue or old one

sivaschenko commented 4 years ago

@okorshenko this is not a regression issue, old one. Looks like we have not faced an image without category before