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()

Comments

jojonaloha created an issue. See original summary.

jojonaloha’s picture

Status: Active » Needs review
StatusFileSize
new1.53 KB

Attached 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 $file is not an object. If this approach is acceptable then the change to views_handler_field_file_rendered::render() shouldn't be necessary.

tnathanjames’s picture

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

dave reid’s picture

Status: Needs review » Needs work
+++ b/file_entity.file_api.inc
@@ -225,6 +225,10 @@ function file_build_content($file, $view_mode = 'full', $langcode = NULL) {
diff --git a/views/views_handler_field_file_rendered.inc b/views/views_handler_field_file_rendered.inc

diff --git a/views/views_handler_field_file_rendered.inc b/views/views_handler_field_file_rendered.inc
index d677374..b062c61 100644

index d677374..b062c61 100644
--- a/views/views_handler_field_file_rendered.inc

--- a/views/views_handler_field_file_rendered.inc
+++ b/views/views_handler_field_file_rendered.inc

+++ b/views/views_handler_field_file_rendered.inc
+++ b/views/views_handler_field_file_rendered.inc
@@ -39,7 +39,8 @@ class views_handler_field_file_rendered extends views_handler_field_entity {

@@ -39,7 +39,8 @@ class views_handler_field_file_rendered extends views_handler_field_entity {
   }
 
   function render($values) {
-    $file = $this->get_value($values);
-    return file_view_file($file, $this->options['file_view_mode']);
+    if ($file = $this->get_value($values)) {
+      return file_view_file($file, $this->options['file_view_mode']);
+    }
   }
 }

I 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().

zaurav’s picture

Rolled up the changes from #5 into a patch file.

Tested on my project and it has fixed the issue.

joseph.olstad’s picture

Please base the patch off of file_entity, not your doc root.
Clone file_entity and reroll patch

zaurav’s picture

StatusFileSize
new599 bytes

Sorry about that. Thanks for the comment!

Rerolling:

zaurav’s picture

StatusFileSize
new606 bytes

joseph.olstad’s picture

Status: Needs work » Fixed

Dave Reid again, great work as usual.

Thanks to zaurav for the patch

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.