EntityMalformedException: Missing bundle property

Created on 12 November 2023, about 1 year ago
Updated 16 February 2024, 10 months ago

The pages on my site are shown without the theming, it is a collection of links and data.

I also get this error:

EntityMalformedException: Missing bundle property on entity of type file. in entity_extract_ids() (line 8097 of /home/customer/www/theorichel.nl/public_html/includes/common.inc).

This has been reported before: https://www.drupal.org/project/file_entity/issues/2421609 🐛 EntityMalformedException: Missing bundle property on entity of type file. in entity_extract_ids() Fixed but since that one was obsolete I was recommended to post again.

I am on D 7.98
PHP 7.4.33
File Entity 2.37
Media 2.30

Many thanks

💬 Support request
Status

Active

Version

2.37

Component

Miscellaneous

Created by

🇳🇱Netherlands TheoRichel

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

Comments & Activities

  • Issue created by @TheoRichel
  • 🇳🇱Netherlands TheoRichel

    Thank you very much!

    I have applied this patch: https://www.drupal.org/project/drupal/issues/2931500 🐛 EntityMalformedException: Missing bundle property on entity of type node in entity_extract_ids() line 8097 Needs work as per your suggestion

    and it gave me back my site which is great), though the error message 'EntityMalformedException..) remains on top of my pages.

    When I flush my cache I get:

    Warning: session_set_save_handler(): Cannot change save handler when headers already sent in drupal_session_initialize() (line 245 of /home/customer/www/theorichel.nl/public_html/includes/session.inc).
    Warning: session_start(): Cannot start session when headers already sent in drupal_session_start() (line 304 of /home/customer/www/theorichel.nl/public_html/includes/session.inc).
    Warning: Cannot modify header information - headers already sent by (output started at /home/customer/www/theorichel.nl/public_html/includes/common.inc:1) in drupal_send_headers() (line 1555 of /home/customer/www/theorichel.nl/public_html/includes/bootstrap.inc).
    Warning: Cannot modify header information - headers already sent by (output started at /home/customer/www/theorichel.nl/public_html/includes/common.inc:1) in drupal_send_headers() (line 1555 of /home/customer/www/theorichel.nl/public_html/includes/bootstrap.inc).
    Warning: Cannot modify header information - headers already sent by (output started at /home/customer/www/theorichel.nl/public_html/includes/common.inc:1) in drupal_send_headers() (line 1555 of /home/customer/www/theorichel.nl/public_html/includes/bootstrap.inc).

    ..... and more of the same.

    For the warning Drupal suggests patching the statistics module, but that has alread been done.

  • 🇨🇦Canada joseph.olstad

    I saw this issue myself this weekend, I had to back off some of my custom code that was re-loading the entity, I ended up figuring out that the entity was already there and I didn't need to load it again in my custom code.

    Check your custom code and recent changes that may have brought this issue up?

  • 🇳🇱Netherlands TheoRichel

    Im not smart enough for custom code, but I did remove some modules though I do not know which ones anymore. Can I still see that history in my database?

  • 🇨🇦Canada joseph.olstad

    if you run update.php or drush updb your site should warn you about modules that were removed but not uninstalled.

  • 🇳🇱Netherlands TheoRichel

    I get access denied when I try to run update.php . The rest of the site (be it with the Malformed error and without theming) is accessible.

  • 🇨🇦Canada joseph.olstad

    @TheoRichel,
    You'll need to be logged in with an administrator role to access update.php

    Please try again.

  • 🇳🇱Netherlands TheoRichel

    Sorry but I am logged in. I can install and uninstall modules, always accompanied by the mentioned errors, but it works. Update.php though says access denied.

  • 🇨🇦Canada joseph.olstad

    It's possible that someone intentionally removed Update.php from your build.

    You may want to make sure you're logged in as user id 1 (administrator)
    the drush uli command gives a token that will log you in as user id 1 provided you're logged out before using the token.

  • 🇦🇺Australia Jon Nunan

    After some debugging I found:
    https://api.drupal.org/api/drupal/includes%21entity.inc/function/DrupalD...
    You'll see when building the query it grabs a list of fields from:
    $entity_fields = $this->entityInfo['schema_fields_sql']['base table'];

    For whatever reason, the values in 'schema_fields_sql' do not include the bundle field. So when the file entity is loaded via that controller it will be missing its bundle and trip up entity_extract_ids().

    I think the issue is hook_schema_alter(); should that be in .install or should it be in .module?
    When debugging and clearing cache, I don't hit a breakpoint I place inside `file_entity_schema_alter()` in its current location in the `.install` file. I think that hook only gets picked up if its in the module file? I tried moving the hook to the .module file, and while I now hit the breakpoint I cache clear the issue still remains.

    I found I could fix the issue by just hardcoding the bundle field in the entity_info_alter() but this feels like a hack and there is something else I'm missing

    function file_entity_entity_info_alter(&$entity_info) {
      $entity_info['file']['fieldable'] = TRUE;
      $entity_info['file']['entity keys']['bundle'] = 'type';
      $entity_info['file']['bundle keys']['bundle'] = 'type';
      $entity_info['file']['schema_fields_sql']['base table'][] = 'type';
    
  • 🇨🇦Canada joseph.olstad

    Hmm, ya, strange , try upgrading to 7.x-2.38 and Drupal core to 7.99

    sounds like this is fixable, with that said, this is something I've seen in the past, sounds like it's something that can be fixed outside of file_entity, but with that said, feel free to elaborate a patch if that helps.

  • 🇩🇪Germany Anybody Porta Westfalica

    I'm running into this after updating to 7.x-2.38. Still unclear, why it happens in my case...

  • 🇩🇪Germany Anybody Porta Westfalica

    Any ideas how we can get more information about the root cause?
    May this be a single malformed (file) entity? I see some file entities without type in my file list (fonts and csv's).

  • 🇨🇦Canada joseph.olstad

    @Anybody,
    you could disable the hack and debug entity_extract_ids() in core includes/common.inc

    Try to find out which ones are crashing, work backwards.

    So you're saying you have file entities without type in your file list? fonts and csvs? Maybe you can simply add a type and update your file_managed records that have no type?

    or the file entity records, have to see where that's stored.

Production build 0.71.5 2024