I have a content type with a file field. I have a custom module which implements hook_form_alter() which adds an extra submission handler to the node edit form.

    $form['actions']['submit']['#submit'][] = 'anexar_aplicacion_submit'; 
function anexar_applicayion_submit(&$form, &$form_state) {
  $reto_nid = $form_state['values']['reto_nid'];
  $aplicacion_nid = $form_state['node']->nid;

  $reto = node_load($reto_nid);
  $reto->field_aplicaciones[LANGUAGE_NONE][]['target_id'] = $aplicacion_nid;
  field_attach_update('node', $reto);
  field_attach_presave('node', $reto);
  entity_get_controller('node')->resetCache(array($reto->nid));
}

This exception is thrown when I create a node of this content type, with the file. It is not thrown when the file is not attached to the node.

EntityMalformedException: Missing bundle property on entity of type node in entity_extract_ids() line 7929

Issue fork drupal-2931500

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Augusto182 created an issue. See original summary.

RoslinMary’s picture

Here is the responsible code which is thrown by Drupal core (file: common.inc):

 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']};
  }

When you try to print $form_state['values'] in node, You will get nid under array format. The same when you print $form_state['node'], You will get nid in object format.

In your above example, I understood that you are referring another node id in current node,
$reto_nid = $form_state['values']['reto_nid'];

If Not Kindly let me know, What value you are trying to get ? So that we can proceed further.

MustangGB’s picture

Priority: Critical » Normal

Support requests aren't critical.

mdjamiruddin’s picture

I am also getting the same issue in my project developed in Drupal 7.59 while accessing few particular pages, not for all pages. I am currently investigating on the issue to rectify it.

It would be appreciable if anyone share the reason behind this with possible solutions.

Marco Aurelio Rocca’s picture

Similar case here with me: typeA content is "room", that relates to a possibly present typeB content: "reservation". Reservation content type has RULES LINK assigned, to "cancel reservation". A VIEWS-page-display tries to list all Rooms along with eventually present Reservations --- and, in that case, along with the Rules Link to Cancel Reservation.

All goes well as long as I ONLY list those Rooms for which there are Reservations and their respectiva Cancel rules-link. If I try to include also those Rooms with no Reservations, I get that EntityMalFormedException. If I delete from the View that Cancel-rules-link, I can get listed all Rooms, were they related to a Reservation of not.

I dare to figure that the Rules Link requires the node entity to be raised into memory, as a Parameter. So, if no Reservation is present, no Cancel Reservation rule link can be formed... and it umpolitely crashes.

Version: 7.56 » 7.x-dev

Core issues are now filed against the dev versions where changes will be made. Document the specific release you are using in your issue comment. More information about choosing a version.

Souvik Pal’s picture

I too faced a similar kind of issue. I am on Drupal 7.78. I had a code where the node id was extracted as...
$nodeid = arg(1);
Found that if I had them wrapped in a check condition like this...

if (arg(0) == 'node' && is_numeric(arg(1))) {
    $nodeid = arg(1);
  }

the issue went away.
However, if I modified the check condition in common.inc from

if (!empty($info['entity keys']['bundle'])) {

to

if (!empty($entity->{$info['entity keys']['bundle']})) {

I could simply use $nodeid = arg(1); without the additional check condition i.e.

if (arg(0) == 'node' && is_numeric(arg(1))) {
    $nodeid = arg(1);
  }

This issue has been there for quite some time. I think its worth looking into. It is always recommended and a good practice to use necessary check conditions while writing custom code, in some cases people may miss out such a simple check condition and that would result them in wasting hours behind it.

Souvik Pal’s picture

EntityMalformedException fix for common.inc.

sroy26’s picture

Yes, I too faced a similar issue and the above solution #8 worked for me. Thanks

mmaranao’s picture

I had the similar issue, even updating media and file entity to the latest. The patch didn't apply to my current setup since I don't have it installed in a /docroot folder. So here's the same patch without /docroot.

awaischamp’s picture

Thanks.. #10 worked for me

Liam Morland’s picture

Status: Active » Needs review
bobburns’s picture

Needs to be comitted to core - strill throwing this error, and this patch fixes it

Liam Morland’s picture

Category: Support request » Bug report

I made a merge request containing the patch in #10.

Koen.Holman’s picture

Status: Needs review » Reviewed & tested by the community

We can confirm this patch works

poker10’s picture

Status: Reviewed & tested by the community » Needs work

Yes, the patch is "working" because it is supressing the problem but not solving it. 99% of the cases where we get this error is when the $entity passed to the field_attach_update or field_get_items or similar is incomplete / broken. And these issues are caused by custom code / contrib modules which are not checking values passed to these functions (see #7). I think that without the full example code we cannot know if this is real bug, or problem of the custom code / contrib module.

Anyway, the patch is making the second condition unreachable (if we pass thru !empty() then we cannot reach EntityMalformedException in any case). I think this EntityMalformedException was put there by design so removing it entirely is not a solution. Therefore I am switching this back to NW.

  if (!empty($entity->{$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)));
poker10’s picture

Is not possible this could have something in common with the problem described here? #3166668: PHP7.4 and empty entity_keys for taxonomy term result in notices - e.g. empty $info variable?

hargurpreet’s picture

Issue summary: View changes

I also had a similar issue and tried patch in #10 and it worked for me. Thanks for sharing this patch.

alianov’s picture

updating for version 7.94

Liam Morland’s picture

Now that #3166668: PHP7.4 and empty entity_keys for taxonomy term result in notices is fixed, does the problem in the present issue still exist or was it fixed by that issue?

danyg’s picture

Without the updated patch in #20, I still got the following PHP error:
EntityMalformedException: Missing bundle property on entity of type node. in entity_extract_ids() (line 8090 of /app/docroot/includes/common.inc).

florisg made their first commit to this issue’s fork.

florisg’s picture

Issue summary: View changes

This bug has been around for ages, please merge it while we still support Drupal 7
I merely rerolled #20 against 7.98

florisg’s picture

Title: EntityMalformedException: Missing bundle property on entity of type node in entity_extract_ids() line 7929 » EntityMalformedException: Missing bundle property on entity of type node in entity_extract_ids() line 8097

updated title to correspond with exact line in v7.98
so people who search with google can find the solution

poker10’s picture

@florisg The last merge request(s) are failing tests. So it is not possible to use this patch without additional changes - we need to fix the test failure and then we can consider the next steps (see my comment #17). Thanks!

Anyway, thanks for working on this, but I suppose that the new merge request was not needed, as there is an open merge request from @Liam Morland, which is the same and therefore this one should have been rerolled.

apaderno’s picture

Assigned: Souvik Pal » Unassigned

It seems the issue summary has been lost in one of the previous revisions.

apaderno’s picture

Issue summary: View changes