Hey!
After updating file_entity to 2.0-beta1 my Drupal sites started to throw this EntityMalformedException error. This is pretty bad since the site goes to error state after this. Clearing cache fixes this temporarily, but since I have to do that from drush this requires manual involvement from me every time. Clients aren't very happy.
This isn't at all consistent, it can go like couple of days w/o any errors, and then there can be a day like today, when the log fills with errors. I reuploaded some images to see if there was something in the image files themselves, but to no avail. I also have few sites using the same installation profile and it's consistent between those.
Also I'm on the omega8.cc aegir host if that could have something to do with this. But all this worked perfectly before the last update, and most of the images work perfectly, even the image on that entity where it's attached works just fine. I'm just not able to reproduce this in any other way than waiting that error to pop up and put my sites down.
I edited that entity_extract_ids() to print out debug_backtrace to dblog, to find out the cause of this. See attachment. It seems that it's from entitycache and file_entity. I also load some json feeds via services and sometimes I can see this backtrace in logs but this doesn't cause the whole site to go down.
I'm pretty much lost and out of options here, I have to try and go back to the alpha3 version and see if that works.
Cheers,
Janne
| Comment | File | Size | Author |
|---|---|---|---|
| #51 | file_entity-entity-malformed-exception_2421609_51.patch | 3.16 KB | rickj |
| #13 | Selection_457.png | 198.52 KB | elijah lynn |
| #9 | Capture3.PNG | 27.96 KB | guypaddock |
| #8 | Capture2.PNG | 155.68 KB | guypaddock |
| #8 | Capture.PNG | 26.61 KB | guypaddock |
Comments
Comment #1
jiisuominen commentedComment #2
jiisuominen commentedOh, and this is present also in the latest dev branch.
/ Janne
Comment #3
jiisuominen commentedComment #4
dooug commentedInstalled file_entity (7.x-2.0-beta1+25-dev) and I saw this error:
Comment #5
Exploratus commentedSame here on install via drush.
Comment #6
axlroach commentedProbably a silly question, but did you run update.php after updating the module? After I updated the module, I was getting this same error when attempting to upload a file. I realized that I had forgotten to run the update script, and after `drush updb`, the issue seems to have been fixed.
Comment #7
guypaddock commentedI'm getting this on a fresh profile install with Media and File Entity...
Comment #8
guypaddock commentedOkay, so, this is odd. I stepped through the entire file upload process and the file being uploaded is saved properly, but it's the retrieval from the database that's failing.
It looks like on the fresh install somehow Drupal does not think that file entities are supposed to have a 'type' column (see the screenshot from IntelliJ's debugger). The file is actually recorded in the database properly (see the other screenshot), but Drupal doesn't actually request the type column from the database, which is why
typeis missing, causing the exception (since type is the "bundle property" for a file entity).Curiously, after a cache clear, the fields listing is correct. Somewhere the fields list for the file entity is not being written out correctly.
Comment #9
guypaddock commentedAttached is what the schema looks like after the cache clear.
update.php also does a cache clear, so that would explain why running it would fix the issue.
Comment #10
matthandHi GuyPaddock,
Have you made further progress researching this file_entity bug?
I am getting the same error message while importing file entities using features. I think it's the same problem.
Comment #11
matthandI believe this error is caused by a conflict between file_entity and entity_uuid. After installing entity_uuid the schema object for File Entities loses the fields for bundle type and uuid.
Comment #12
guypaddock commented@BullMoose: That doesn't seem consistent with my own findings. This error will appear immediately after site install and will reappear if you run update.php, but goes away on a cache clear.
It seems that the way that install.php and update.php populate the entity info cache is somehow not "deep" enough and/or misses hooks that are called during a normal cache clear.
Comment #13
elijah lynnFailing for me right now on install because a pre-exisiting file does not have an $entity->bundle at all. The call stack is deep inside a stack started with bean_block_info(). So it may be related to that. Not sure I am going to go deep into debugging this right now but thought I would share my feedback.
FYI, I do not have the entity_uuid module installed.
Update1: Same issue with alpha1, alpha3 and beta1 too.
Comment #14
michee.lengronneIt is a problem in the drupal_get_complete_schema function.
It seems that
drupal_alter('schema', $schema);does not report correctly the alterations (the type column and the uuid column if uuid is used).As a workaround I think we could mask it by an entity_info_alter with the relevant infos.
That's a dirty solution but it seems to work.
Comment #15
dave reidI've seen this before when entity_get_info() is called with a cold cache, before a full bootstrap and all the modules have been loaded. In that case anything invoking hook_schema_alter() would not get called.
Comment #16
michee.lengronneIt seems a more global issue as I had the same problem with other entity types (schema_alter not taken into account). I think we should put this issue in core.
Comment #17
davidwbarratt commentedWas anyone able to resolve this issue?
Comment #18
sch2 commented#14 does seem to be working, just have uuid module enabled before clearing caches, or some db hacking will be required
Comment #19
davidwbarratt commentedI have a theory that this is related to Entity Cache. I think the bad file entity is being loaded into cache, and when it's read from the cache, the exception is thrown.
Is anyone else using Entity Cache?
Comment #20
davidwbarratt commentedDisabling Entity Cache didn't fix the issue, but here's a stack trace:
It looks like the problem is with core, Media, FIle Entity, or Views.
Comment #21
joelpittetI ran into this problem with commerce discounts. Sharing to give some hints for people faced with this.
I had a database transaction nested on load
commerce_orderentity, then inside that transaction acommerce_line_itementity controller started a new transaction to save a new line item. It would save a line item, store that onentityCache(including theline_item_id) before the database commit happened. The next thing that tried to load another order entity was still inside the top transaction and tried to load a order entity from the database in which it wasn't there and threw 'Missing bundle property on entity of type commerce_line_item'.Transaction layers looked like this:
Where
drupal_transactionwas shared between the first order load and the save and the next load.In my case it was due to a locking patch I was testing, but I could see this happening in any situation where you have reads and writes inside of transactions.
Comment #22
davidwbarratt commentedHere's a truncated backtrace... It seems really odd that the file object would only have the
altkey.Comment #23
guypaddock commentedWe aren't using Entity Cache either, but saw this here too. It really does seem like Drupal is caching the entity info before the modules are loaded. It only seems to happen when the cache is rebuilt from
update.phpor any script that's not fully bootstrapped.Comment #24
davidwbarratt commentedI found the problem!
In template_preprocess_media_views_view_media_browser() you have this:
but since the view result and the rendered output are cached separately, if the rendered output is cleared before the view output is cleared then their are
fid's in the view result that no longer exist in the database. file_load_multiple() only returns files that are actually in the database (and doesn't do anything if you pass an invalid id in), and since there is no check to make sure the index actually exists, the second part of the code passesNULLinto media_browser_build_media_item(), which then throws an exception later down the line.I hope this is a good lesson to everyone of why you don't execute database queries at the template/theme level. :)
I realize that this isn't exactly the problem the OP had. Not sure if this issue should be moved to Media or a new one should be created over there.
Comment #25
davidwbarratt commentedSince my issue isn't exactly what the OP posted, I've opened #2659876: EntityMalformedException: Missing bundle property on entity of type file. in entity_extract_ids() to cover the issue I'm having.
Comment #26
guypaddock commentedYeah, @davidwbarratt, definitely does not seem to be what we've been talking about in this thread. The issue we're running into looks like something that's affecting Core's ability to properly cache entity information during partially-bootstrapped requests.
Comment #27
leisurman commentedSame error for me.
EntityMalformedException: Missing bundle property on entity of type node. in entity_extract_ids() (line 7880 of /var/www/html/d3/includes/common.inc).
my content page says error:
/admin/content
when i hit this page I get the Missing bundle error
I tried this commons patch without success
https://www.drupal.org/files/issues/empty_string_bundle.patch
This is a d6 to d7 upgraded site with 5000 nodes, im using
File Entity 7.x-2.0-beta2
Media 7.x-2.0-beta1
I do not have the entity_uuid or Entity Cache module installed.
Chaos tools 7.x-1.9
I had two missing columns from file_managed at one time, type and uuid. I created them.
Im comparing my site to a fresh clean d7 site that doesn't have the error and I think this could be bad content?
Comment #28
leisurman commentedThis issue has been around for 5 years!
https://www.drupal.org/node/1266620
Comment #29
leisurman commentedI tried the media patch from here, but still have the error
https://www.drupal.org/node/2659876/revisions/9334224/view
Im using Centos7
php4.5
maraidb
Comment #30
leisurman commentedI tried to use
Media 7.x-2.0-alpha3
File entity 7.x-2.0-beta1
Same problem. as soon as i disable file entity the content page works and the bundle error goes away
Comment #31
letapjar commentedThis annoying bug pops up everywhere.
The DrupalDefaultEntityController calls field_attach_load as part of it's own attachLoad method
It seems that field_attach_load (line 688) calls entity_extract_ids() but HOOK_field_attach_load does not fire until line 718.
Here's a potential workaround:
The default entity controller tags it's select query with {entity_type}._LOAD_MULTIPLE
Thus we can implement file_entity_query_file_load_multiple_alter($query){
}
and explicitly add in the 'type' field so that the correct field is pulled from the database regardless of execution order.
Comment #32
letapjar commentedforgot to change issue to "needs Review" - re patch #31
Comment #34
letapjar commentedhmm.. not sure why the automated test said the patch was invalid - could someone take a look to see if there is an obvious error? I haven't used the automated test system much so I don't know if there's a basic formatting problem here. The code works on my live site though
Comment #35
dqdI sadly have to confirm this bug on every second D7 project atm. It causes SWOD on cron job via page link and interrupts cron via Drush with:
Another question: Since I saw a similar Error in the issue queue of core, but regarding nodes instead of files and by reading thru it, I would like to ask if you all encounter this error on long living projects or also on new setup projects, since the node issue certainly is connected to any orphaned entities.
Comment #36
ilari.stenroth commentedI fixed similar issue with file_entity 7.x-2.0-beta2 with my patch. It seems that there can be multiple reasons why this error occurs but in my case I believe a deleted file was still referenced somewhere.
Comment #37
ilari.stenroth commentedMy patch #36 is flawed. Don't use it.
Comment #38
rickj commentedI've been running into this error recently, and turns out it's since upgrading to 7.x-2.0-beta3.
I specifically encounter it when attaching files to comments, but I'm sure it crops up in other situations. The source of the problem is in the changes to file_entity.field.inc. In particular this line (310):
$file = (object) $item;The cast is a hack, $item at this point is not a file object at all, it's just an array that includes the file's fid. It should be:
$file = file_load($item['fid']);This is effectively what's in beta2, although the logic has been substantially re-arranged.
Patch file attached.
Comment #39
joelpittetComment #41
matthewmessmer commentedPatch #38 applied cleanly and fixed this issue for me.
Comment #42
interdruper commentedIn my particular case, #38 does not fix the issue. Moreover, it raises a couple of additional warnings:
Comment #43
rickj commented@interduper - exactly what version of file-entity are you using? The patch was made against 7.x-2.0-beta3+3-dev, and the error report on line 315 doesn't quite match up.
In what circumstance do you get the error? My problem was on uploading attachments, is yours a different case?
Comment #44
chroid commentedI can confirm that the patch in #38 fixes the issue where we had the following error:
Occurred in an update from 7.x-2.0-beta2 to 7.x-2.0-beta3.
Comment #45
clairedesbois@gmail.comI have the same error but I know how it happens. Apparently, when we delete entity files on the system, entities which refer to these files are broken when we display them. If I look the database, I see in the entity references fields the fid is present. But the corresponding file doesn't exist anymore.
If I study my entity with devel, I will see my field has an empty object instead of the entity file.
The patch #38 doesn't works in my case but, I added a condition file_entity_field_formatter_view() in to verify for each item if it's not an empty item. If it's the case, it's probably a reference to a deleted file so I add an error in the watchdog. My patch works if your file field is multivalue and just ignore missing files.
Maybe we should add a patch to clean references on files when we delete them but I don't look where it is managed.
Comment #46
clairedesbois@gmail.comComment #47
rickj commented@Calystod - good call, I haven't encountered that use case, but seems to correspond to other reports involving deleted files. This has clearly been a troublesome bit of code.
I will try to have a look at where it might be possible to clean up broken references. When you have been deleting files, is this under admin/content/file, or by some other method?
Comment #48
gooddesignusa commentedI ran in to this issue when using the paragraphs module with a image field using the media browser widget. If I tried to hit the collapse button it would cause an ajax error alert with this error. After applying patch from #45 the error went away and I was able to use the paragraph module with media widget field types. Thanks Calystod!
Comment #49
alauddin commentedReverting to file_entity 7.x-2.0-beta2 worked for me
Comment #50
mausolos commentedI ran into this while wrangling with apachesolr/apachesolr_user. After adding a custom user photo field to the Display Suite "Search Index" user display, I got this error when trying to run a batch reindex. Applying #45 resolved the issue. Thanks!
Comment #51
rickj commentedAfter applying patch #45 I looked at the code and the indenting was rather messy. Turns out the patched code uses tabs for indents, contrary to Drupal coding guidelines (but something I've been guilty of myself in the past!).
I've reworked the patch to use spaces in official Drupal style, attached here. No change in functionality, just neater code layout.
BTW, this, and patch #45, both incorporate the separate fix I posted in #38, so only one patch needs to be applied.
Comment #52
dieuweI ran into this problem and after hours of debugging came up with the same fix at #38, but the more comprehensive patch from #51 applies and doesn't give any problems either.
My case it came up after nesting an image field inside a custom file type and the entire object wasn't being passed through (just the file ID).
Comment #53
dman commentedTo add to the noise (there are various causes to this symptom) ..
I've been able to replicate the situation described by @Calystod in #45.
Due to years of oddness in a (migrated from D6) site, it's not impossible for our Database integrity to be a little crap - and we have file field references to a ->fid that no longer exists.
Core quietly ignores those issues (yet does not warn or repair)
file_entity crashes hard.
Looking at devel dump of one of these bad nodes:
.. where the usual assumption is that an empty field would not even have that 0=>NULL there.
I traced that back to file_field_load() that handles a failure inside file_load_multiple (and invalid fid) thus:
As identified in this issue and patches above - this then explodes when file_entity_field_formatter_view() does a
without noticing that $item was NULL.
For me (my situation was different from the cache or recursion issues above, but had a similar cause) I'm having to inject
.. and now I also have to go and find a way to clean up those integrity issues in the old source data...
* Unexpected input = root cause
* Crashing hard on unexpected input = bad behaviour
Comment #54
noel.rivas commentedI can confirm that #38 is solving the issue in my case. Thanks, Rick!
Comment #55
brockfanning commentedAs has been mentioned there are various possible reasons for this error. For me, it is the problem of drupal_get_schema returning un-altered (not affected by hook_schema_alter) data after a full cache clear, which was alluded to in #15. This causes DrupalDefaultEntityController::buildQuery to only query the core managed_file columns, leaving out "type" which is normally added in file_entity_schema_alter(). Here is a snippet that fixes that problem, though I don't know if it makes sense to go into this patch. (Probably not, as this does seem like something that belongs more in core, as mentioned in #16.)
All that aside, I did test out the patch in #51, and although it didn't fix my particular issue, it didn't cause any additional problems.
Comment #56
mellowtothemax commented#51 fixed my issue, I deleted multiple files from the media module that caused the problem.
Thank you
Comment #57
joseph.olstadSubscribing. I've seen this issue before, next time it occurs I will try this patch.
Comment #58
joseph.olstad#51 fixed our issue as well. Please commit. Without this patch somehow some nodes got messed up, the node view crashed with this error (as described above) and had to go to the admin theme and edit the node reattaching the file before it would be viewable. Patching/committing is the way to go.
Thanks
Comment #59
joseph.olstadComment #60
jrglasgow commentedPatch #51 fixed my issue, please commit
Comment #62
joseph.olstadComment #64
theorichel commentedHello,
I am having the same problem
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).
and since this thread is years old, I do not know what to do. Apply patch 51?
I am on D 7.98
PHP 7.4.33
File Entity 2.37
Media 2.30
Many thanks in advance.
Comment #65
theorichel commentedI am applying the patch in #51 which wants me to remove several lines with the word 'recursive' in it but that word is not in the 2.37 v of the file, the word 'repeated' is. Which word should I use? 'Recursive' from the patch or should I replace that 'Recursive' from the patch with 'repeated'.?
Thanks!
Comment #66
rickj commented@TheoRichel
This issue was raised against 7.x-2.0-beta3, the current version is 7.x-2.37. The fix here is already incorporated in 2.37, so the patch is not relevant. Are you running the latest version?
It sounds to me that another bug may have crept in that's resulting in the same error message. It would be best to open a new issue, and describe how to replicate the problem.
Comment #67
theorichel commentedI reposted: https://www.drupal.org/project/file_entity/issues/3401100
Thanks
Comment #68
joseph.olstad