EntityMalformedException: Missing bundle property on entity of type relation. in entity_extract_ids()

Created on 5 January 2023, almost 2 years ago
Updated 4 June 2023, over 1 year ago

Problem/Motivation

EntityMalformedException: Missing bundle property on entity of type relation. in entity_extract_ids() (line 8072 of /app/web/includes/common.inc).

Steps to reproduce

Create rules to fetch 'rid' from the relation

Proposed resolution

entity_extract_ids() in common.inc uses entity object without wrapper to validate.

  if (!empty($info['entity keys']['bundle'])) {
    // Explicitly fail for malformed entities missing the bundle property.
    if (!isset($entity->{$info['entity keys']['bundle']}) || $entity->{$info['entity keys']['bundle']} === '') {
      throw new EntityMalformedException(t('Missing bundle property on entity of type @entity_type.', array('@entity_type' => $entity_type)));
    }
    $bundle = $entity->{$info['entity keys']['bundle']};
  }

Relation entity with wrapper

relation_rules_load_related()
        foreach ($related_entities as $related_entity) {
          if (empty($entity_type_op) || $entity_type_op == $property['target_type']) {
            $endpoint_wrapper = entity_metadata_wrapper($property['target_type'], $related_entity);
            if ($endpoint_wrapper->type() != $source_entity_type || $endpoint_wrapper->getIdentifier() != $source_entity_id) {
              $endpoints[] = $endpoint_wrapper;
            }
          }
        }

Solution
We can simply send an entity object without a wrapper that will resolve this issue,

🐛 Bug report
Status

Needs review

Version

1.2

Component

Entity API / Rules

Created by

🇮🇳India harivansh

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024