Cannot load the "civicrm_entity_tag" entity with NULL ID

Created on 15 May 2024, about 1 month ago
Updated 4 June 2024, 19 days ago

Problem/Motivation

After adding a tag to the contact and then removing it, we receive an error.

AssertionError: Cannot load the "civicrm_entity_tag" entity with NULL ID. in assert() (line 261 of core/lib/Drupal/Core/Entity/EntityStorageBase.php).

Drupal\Core\Entity\EntityStorageBase->load(NULL) (Line: 488)
civicrm_entity_civicrm_pre('delete', 'EntityTag', NULL, Array) (Line: 284)
CRM_Utils_Hook->runHooks(Array, 'civicrm_pre', 4, 'delete', 'EntityTag', 6, Array, NULL, NULL) (Line: 73)
CRM_Utils_Hook_DrupalBase->invokeViaUF(4, 'delete', 'EntityTag', 6, Array, NULL, NULL, 'civicrm_pre') (Line: 322)

Steps to reproduce

1. Add contact in CiviCRM.
2. Add tag to contact.
3. Save contact.
4. Edit contact and remove tag.
5. An error occurs.

Proposed resolution

To fix that, we need to make changes in civicrm_entity.module file in line 480 from:

    if ($objectName == 'EntityTag') {
      $id = $storage->getEntityTagEntityId($params[0][0], $params[1]);
    }

To:

    if ($objectName == 'EntityTag') {
      $id = $storage->getEntityTagEntityId($params['entity_id'], $params['entity_table']);
    }

Or with saved back compatibility:

if (isset($params['entity_id']) && isset($params['entity_table'])) {
  $id = $storage->getEntityTagEntityId($params['entity_id'], $params['entity_table']);
}
else {
  $id = $storage->getEntityTagEntityId($params[0][0], $params[1]);
}
πŸ› Bug report
Status

Fixed

Version

4.0

Component

Code

Created by

πŸ‡΅πŸ‡±Poland michal_liszka

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

Comments & Activities

Production build 0.69.0 2024