Hi,

Awesome module!... :)

D7: 7.14
Version: 7.x-1.0-beta5+6-dev
Error:
EntityMalformedException: Missing bundle property on entity of type node. in entity_extract_ids() (line 7539 of /home/server/.drupal/7/development/drupal-7.14/pressflow/demo/includes/common.inc).

I got this right after I saved the settings. I've seen this error from other modules and I've read Drupal is forcing a more strict coding standarded which: I believe should have been done along time ago, but is there a patch for this?

Here is the function calling this error:

function entity_extract_ids($entity_type, $entity) {
  $info = entity_get_info($entity_type);

  // Objects being created might not have id/vid yet.
  $id = isset($entity->{$info['entity keys']['id']}) ? $entity->{$info['entity keys']['id']} : NULL;
  $vid = ($info['entity keys']['revision'] && isset($entity->{$info['entity keys']['revision']})) ? $entity->{$info['entity keys']['revision']} : NULL;

  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']};
  }
  else {
    // The entity type provides no bundle key: assume a single bundle, named
    // after the entity type.
    $bundle = $entity_type;
  }

  return array($id, $vid, $bundle);
}

Thanks!

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

amitaibu’s picture

Priority: Critical » Normal

Are you sure the referenced node does have a non-deleted node-type?

Vc Developer’s picture

FileSize
1.07 MB

Hi, thanks for the reply!

This is a fresh install to find out why I was getting this message when I was trying to do a preview. Because before is was working fine, but don't know if any of the other modules I added caused the problem. I've attached a PDF of what modules I have enabled thus far after the fresh install. Now I get the message every time I try to save or edit the field.

I will eliminate mod's from this point and see what happens.

P.S. I'm using the References Module now and its working perfectly, but would like to return back because I understand this will be the future for this type.

Vc Developer’s picture

Hi,

I just finished doing a new D7.14 install and only enabled CTools and Entity API with the same results.... :(

abtm’s picture

I am having the same problem. It works fine with 7.x-1.0-rc1. This problem occurred after I upgraded it to 7.x-1.x-dev. Any ideas on what's going wrong?

Offlein’s picture

Same thing! Fresh install, right after I added my first Entity Reference field. I have a very basic selection of modules enabled.
Also! My entity was a USER, not a NODE.

bojanz’s picture

This was introduced by:

commit a7c9f9567597db14c1dec0bd78a78fd3c361a45f
Author: Damien Tournoud <damien@commerceguys.com>
Date:   Wed May 9 21:21:21 2012 +0200

   Issue #1555894: pass the entity context to selection handlers.

At the top of entityreference_field_widget_form() the $entity gets initialized to NULL because $element['#entity'] is missing, which gets passed to entity_extract_ids, which chokes.

EDIT: Okay, that was because the install wasn't on Drupal 7.14, and the latest Entityreference -dev requires Drupal 7.14, because that's when $element['#entity'] was introduced. So there needs to be a hook_requirements() / info file dependency for Drupal 7.14.

amitaibu’s picture

Status: Active » Needs review
FileSize
707 bytes

This happens also on 7.14, when adding a new field. Attached patch checks $entity exists before doing entity_extract_ids()

abtm’s picture

1576664-entity-null-7.patch breaks my site.

amitaibu’s picture

Abtm, I'll need more info...

owntheweb’s picture

I seem to be having the same issue. My install is not fresh, but all my modules and Drupal core are up-to-date at 7.14. The problem started happening when trying to delete nodes after upgrading/updating everything from 7.12 to 7.14. Let me know what kind of specifics I can provide on this. :)

abtm’s picture

After I applied the patch in #8 last time, my site went blank. Tried a few times the got the same result. Then I reported it. But today after I applied it once again it worked. The error msg doesn't come out any more. No clue....

MXT’s picture

I've had the same error, but patch in #7 resolved it.

The error occurred when tried to edit an existing entity reference field.

Damien Tournoud’s picture

Status: Needs review » Needs work
+    if ($entity) {
+      list($id) = entity_extract_ids($entity_type, $entity);
+      $autocomplete_path .= '/' . $id;
+    }

This doesn't look correct. We do need the additional / even when the entity is not defined.

MegaChriz’s picture

Status: Needs work » Needs review
FileSize
990 bytes

The attached patch fixes the issue noted in #13. The additional / is added to the line above.

checker’s picture

#14 is working for me.

mikemadison’s picture

The patch does NOT seem to be working for me. I am still getting the error after applying it. I originally got the error using RC1, and I upgraded to Dev, then applied the patch. Anyone else confirm or deny if this fixed their problem?

mikemadison’s picture

Actually, in digging a bit more, it looks like other factors may play into this bug than just entity reference. I didn't have that module enabled at first and I was still getting this same error.

mikemadison’s picture

See http://drupal.org/node/1277376#comment-5925664 for another possible solution, if you are like me and are having this particular error even when you don't have modules enabled.

checker’s picture

I tested it with current dev

Anonymous’s picture

#14 works for me, too (current dev)

Arrow’s picture

#14 worked on the current dev!

klucid’s picture

Patch #14 did not fix the problem. Actually, updating the the dev broke my site.

Fatal error below:

Fatal error: Declaration of OgSelectionHandler::getInstance() must be compatible with that of EntityReference_SelectionHandler::getInstance() in /home/public_html/p5/sites/all/modules/og/plugins/entityreference/selection/OgSelectionHandler.class.php on line 7

Edit: Confirming that it was the dev version of the module that broke the site. Undid patch, same error, reinstalled RC1 and it's back to normal.

klucid’s picture

For what it's worth:

For the people trying to delete user accounts, if you select "Delete the account and make its content belong to the Anonymous user," the deletion goes through successfully.

Hope this helps.

Anonymous’s picture

Anonymous’s picture

Status: Needs review » Reviewed & tested by the community
GiorgosK’s picture

#14 works great

Damien Tournoud’s picture

Status: Reviewed & tested by the community » Fixed

Merged into 7.x-1.x, thanks!

Preston McMurry’s picture

I do not have entityreference module installed, yet still get the error on line 7539 of common.inc in Drupal 7.14. Further details here: http://drupal.org/node/1277376#comment-6095438

Perhaps entityreference is not the only module that requires this (or a similar) patch. What should I grep the codebase for to find other places to patch?

Anonymous’s picture

For sure entityreference is not the only module. The error occurs when calling entity_extract_ids() without proper $entity. You need to find out who's breaking the entity. According to your posting in the other issue, you could follow field_attach_update() until you hit entity_extract_ids() or enable a call stack somehow. Just in case the entity you pass in is intact.

Status: Fixed » Closed (fixed)

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

HongPong’s picture

This may be a tangent but if you have malformed files entities - see #1446440: Unable to view me media management pages (EntityMalformedException: Missing bundle property...) for my one-off SQL fix for column type in the files_managed table.

lshao999’s picture

Project: Entity reference » Read More Control
Issue tags: +EntityMalformedException, +Read More Control

#14 patch works for me. After the patch, a dozen error messages were displayed, revealing the real culprit (Read more control module). After disabling the module, everything is normal. (My project has updated to core 7.15)

Alan D.’s picture

Status: Closed (fixed) » Postponed (maintainer needs more info)

Hi, just wondering why this was transferred to this queue?

What is the issue and how would I replicate it? The EntityMalformedException is an exception thrown when the entity is not loaded completely and then used in the entity system functions. (i.e. it is very generic)

Have you have a copy of the notices that this module was throwing?

clashar’s picture

I have no "Read More Control" module, so it's not issue for this project.

Anonymous’s picture

Project: Read More Control » Entity reference
Status: Postponed (maintainer needs more info) » Closed (fixed)

Would you please stop adding new comments here and read back to #29.

The original issue was in the responsibility of Entity reference and it really is already solved.

Please understand: the same error message can result from any module calling entity_extract_ids().

If you're seeing the error again, go find out who causes it. If you can't, go find someone who can. But do not ever touch this issue.

Oh wow, this feels like talking to my little daughter. :)

DevElCuy’s picture

Hint for the ones that still get this error.

I'm building a batch import script with migrate module. Got this error when inserting 0 to an entityrefence field, so what I did is to patch my source SQL query, making it translate 0 to NULL, so the field is processed as empty and not as having an invalid value.

bendiy’s picture

Status: Closed (fixed) » Needs review
FileSize
552 bytes

I'm still getting this error on some use cases. I think the root cause is that you're using '$instance['entity_type']' when you should use '$element['#entity_type']'.

The field options module does it like this:
http://drupalcode.org/project/drupal.git/blob/refs/heads/7.x:/modules/fi...

$entity_type = $element['#entity_type'];

See attached patch.

Chris Matthews’s picture

Status: Needs review » Needs work
Issue tags: -EntityMalformedException, -Read More Control +Needs reroll

The 5 year old patch in #37 to entityreference.module does not apply to the latest 7.x-1.x-dev and if still relevant needs a reroll.

Checking patch entityreference.module...
error: while searching for:
  if (empty($entity_info)){
    return;
  }
  $entity_type = $instance['entity_type'];
  $entity = isset($element['#entity']) ? $element['#entity'] : NULL;
  $handler = entityreference_get_selection_handler($field, $instance, $entity_type, $entity);

error: patch failed: entityreference.module:796
error: entityreference.module: patch does not apply
Mile23’s picture

Issue tags: -Needs reroll
FileSize
553 bytes

Reroll of #37 against current dev.

Also applies to 7.x-1.5.

Also note: This didn't solve the problem for me. :-)

Mile23’s picture

Status: Needs work » Needs review