Problem/Motivation
The page (render) cache is cached separately from the view result. If a user opens the media browser, everything gets put into both caches, however, if someone deletes a file that is in the view result, this exception is thrown when you reload the media browser:
EntityMalformedException: Missing bundle property on entity of type file. in entity_extract_ids()
This happens because of this code in template_preprocess_media_views_view_media_browser():
$files = file_load_multiple($fids);
// Render the preview for each file.
$params = media_get_browser_params();
$view_mode = isset($params['view_mode']) ? $params['view_mode'] : 'preview';
foreach ($vars['rows'] as $index => $row) {
$file = $files[$row->fid];
// Add url/preview to the file object.
media_browser_build_media_item($file, $view_mode);
$vars['rows'][$index] = $file;
$vars['rows'][$index]->preview = $file->preview;
}
Since the query result is cached, and a fid from that result has been deleted, then file_load_multiple() will not return the same list of files that was passed into it.
Then the first argument passed to media_browser_build_media_item() is NULL
Proposed resolution
Ideally, we shouldn't be making database queries from the theme/template layer, but since changing that would take a major refactoring, it seems wiser to simply add a check that would ensure that the file being accessed actually exists in the array.
Remaining tasks
Write Patch
User interface changes
None.
API changes
None.
Data model changes
None.
Comment | File | Size | Author |
---|---|---|---|
#3 | media-entity_exception-2659876-3.patch | 675 bytes | davidwbarratt |
|
Comments
Comment #2
davidwbarratt CreditAttribution: davidwbarratt at Golf Channel commentedComment #3
davidwbarratt CreditAttribution: davidwbarratt at Golf Channel commentedAttached is a patch that fixes the problem.
Comment #4
davidwbarratt CreditAttribution: davidwbarratt at Golf Channel commentedComment #5
Dave ReidComment #7
Dave Reid