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!

Files: 
CommentFileSizeAuthor
#37 entityreference-entity-null-1576664-37.patch552 bytesbendiy
PASSED: [[SimpleTest]]: [MySQL] 121 pass(es).
[ View ]
#14 entityreference-entity-null-1576664-14.patch990 bytesMegaChriz
PASSED: [[SimpleTest]]: [MySQL] 66 pass(es).
[ View ]
#7 1576664-entity-null-7.patch707 bytesAmitaibu
PASSED: [[SimpleTest]]: [MySQL] 66 pass(es).
[ View ]
#2 Modules _ Enabled.pdf1.07 MBVc Developer
entity2.jpg53.04 KBVc Developer
entity1.jpg42.26 KBVc Developer

Comments

Priority:Critical» Normal

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

StatusFileSize
new1.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.

Hi,

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

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?

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.

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.

Status:Active» Needs review
StatusFileSize
new707 bytes
PASSED: [[SimpleTest]]: [MySQL] 66 pass(es).
[ View ]

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

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

Abtm, I'll need more info...

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. :)

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....

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

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

Status:Needs review» Needs work

<?php
+    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.

Status:Needs work» Needs review
StatusFileSize
new990 bytes
PASSED: [[SimpleTest]]: [MySQL] 66 pass(es).
[ View ]

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

#14 is working for me.

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?

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.

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.

I tested it with current dev

#14 works for me, too (current dev)

#14 worked on the current dev!

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.

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.

Status:Needs review» Reviewed & tested by the community

#14 works great

Status:Reviewed & tested by the community» Fixed

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

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?

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.

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.

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)

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?

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

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. :)

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.

Status:Closed (fixed)» Needs review
StatusFileSize
new552 bytes
PASSED: [[SimpleTest]]: [MySQL] 121 pass(es).
[ View ]

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.