I somehow ended up with an entry in commerce_product__variations with a variations_target_id referencing a deleted variation.

Deleting said product programmatically then results in:

TypeError: get_class(): Argument #1 ($object) must be of type object, null given in /app/web/core/lib/Drupal/Core/Entity/EntityStorageBase.php on line 688 #0 /app/web/core/lib/Drupal/Core/Entity/EntityStorageBase.php(688): get_clas
s(NULL)
#1 /app/web/core/lib/Drupal/Core/Entity/EntityStorageBase.php(480): Drupal\Core\Entity\EntityStorageBase->getEntitiesByClass(Array)
#2 /app/web/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php(751): Drupal\Core\Entity\EntityStorageBase->delete(Array)
#3 /app/web/modules/contrib/commerce/modules/product/src/Entity/Product.php(312): Drupal\Core\Entity\Sql\SqlContentEntityStorage->delete(Array)
#4 /app/web/core/lib/Drupal/Core/Entity/EntityStorageBase.php(494): Drupal\commerce_product\Entity\Product::postDelete(Object(Drupal\commerce\CommerceContentEntityStorage), Array)
#5 /app/web/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php(751): Drupal\Core\Entity\EntityStorageBase->delete(Array)
#6 /app/web/core/lib/Drupal/Core/Entity/EntityBase.php(347): Drupal\Core\Entity\Sql\SqlContentEntityStorage->delete(Array)
#7 /app/web/core/modules/migrate/src/Plugin/migrate/destination/Entity.php(217): Drupal\Core\Entity\EntityBase->delete()
#8 /app/web/core/modules/migrate/src/Plugin/migrate/destination/EntityContentBase.php(395): Drupal\migrate\Plugin\migrate\destination\Entity->rollback(Array)

I do not know how to reproduce this invalid state.
But I'd like to offer a patch to at least be able to delete it successfully.

CommentFileSizeAuthor
commerce_cannot_delete_product.patch947 bytesfougere

Issue fork commerce-3445520

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

fougere created an issue. See original summary.

abhishek_gupta1’s picture

Assigned: Unassigned » abhishek_gupta1

abhishek_gupta1’s picture

Assigned: abhishek_gupta1 » Unassigned
Status: Active » Needs review

@rszrama , I have verified above patch, its working for me , also I created MR.

jsacksick’s picture

Status: Needs review » Fixed

Merged, thanks.

abhishek_gupta1’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.