Drupal\file\FileUsage\DatabaseFileUsageBackend::listUsage(): Argument #1 ($file) must be of type Drupal\file\FileInterface, null given

Created on 15 March 2024, 8 months ago
Updated 16 September 2024, 2 months ago

Problem/Motivation

The following exception is thrown because the thumbnail might occassionally be null, so needs proper handling for it:

[error]  TypeError: Drupal\file\FileUsage\DatabaseFileUsageBackend::listUsage(): Argument #1 ($file) must be of type Drupal\file\FileInterface, null given, called in /app/application/web/modules/contrib/media_thumbnails/src/Plugin/MediaThumbnailManager.php on line 140 in Drupal\file\FileUsage\DatabaseFileUsageBackend->listUsage() (line 101 of /app/application/web/core/modules/file/src/FileUsage/DatabaseFileUsageBackend.php) #0 /app/application/web/modules/contrib/media_thumbnails/src/Plugin/MediaThumbnailManager.php(140): Drupal\file\FileUsage\DatabaseFileUsageBackend->listUsage(NULL)
#1 /app/application/web/modules/contrib/media_thumbnails/media_thumbnails.module(48): Drupal\media_thumbnails\Plugin\MediaThumbnailManager->deleteThumbnail(Object(Drupal\media\Entity\Media))
#2 [internal function]: media_thumbnails_media_delete(Object(Drupal\media\Entity\Media))

Steps to reproduce

Attempt to delete a media entity that does not have a thumbnail attached for whatever reason.

Proposed resolution

Return early if the media entity has no thumbnails attached.

Remaining tasks

Provide issue fork/patch.

User interface changes

N/A

🐛 Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024