I was getting the following errors:
Notice: Trying to get property of non-object in file_view_file() (line 226 of drupal/sites/all/modules/contrib/file_entity/file_entity.file_api.inc).
Warning: Creating default object from empty value in media_file_displays_alter() (line 1165 of drupal/sites/all/modules/contrib/media/media.module).
EntityMalformedException: Missing bundle property on entity of type file. in entity_extract_ids() (line 7879 of drupal/includes/common.inc).
Using:
- Drupal 7.41
- File Entity 7.x-2.0-beta2
- Media 7.x-2.0-beta1
I think the problem is that I have a View with a "File: Rendered" field configured with Query results caching on. When I remove one of the files I get this error for a short period until the View cache expires (5min in my case).
Looking at views_handler_field_entity::get_value() and views_plugin_query_default::get_result_entities() both may return FALSE under certain conditions which are not handled in either views_handler_field_file_rendered::render() or file_view_file()
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | file_entity-EntityMalformedException-2644846-8.patch | 606 bytes | zaurav |
| #3 | file_entity-entitymalformedexception-2644846-3-d7.patch | 511 bytes | tnathanjames |
| #2 | file_entity-entitymalformedexception-2644846-2.patch | 1.53 KB | jojonaloha |
Comments
Comment #2
jojonaloha commentedAttached is a patch to try to handle this and other possible instances when $file is not a file object.
In
file_view_file()I return early if$fileis not an object. If this approach is acceptable then the change toviews_handler_field_file_rendered::render()shouldn't be necessary.Comment #3
tnathanjames commentedI was about to post a similar issue and patch before I found this. My error is actually consistent because I have a view that uses a relationship from terms to files that reference the term, but doesn't require it. So, for terms that haven't been selected in any of the files, a result row is generated where FALSE is passed to file_view_file instead of a file object. Since you indicate above that the second part of the patch may not be necessary, I am posting the return early part by itself here.
Comment #4
joelstein commentedThis might be related to #2737817-8: Undefined property: stdClass::$fid in file_build_content() (line 173.
Comment #5
dave reidI would prefer just having this change. Places where we pass an empty file object need to be fixed where it happens, instead of hiding the error in file_view_file().
Comment #6
zauravRolled up the changes from #5 into a patch file.
Tested on my project and it has fixed the issue.
Comment #7
joseph.olstadPlease base the patch off of file_entity, not your doc root.
Clone file_entity and reroll patch
Comment #8
zauravSorry about that. Thanks for the comment!
Rerolling:
Comment #9
zauravComment #12
joseph.olstadDave Reid again, great work as usual.
Thanks to zaurav for the patch