Cannot delete product programmatically: 'get_class(): Argument #1 ($object) must be of type object, null given in get_class()'

Created on 6 May 2024, 8 months ago
Updated 21 May 2024, 7 months ago

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.

🐛 Bug report
Status

Fixed

Version

2.33

Component

Product

Created by

🇫🇷France fougere

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024