Problem/Motivation

This is a followup of #3059950: Media sources should handle empty source field values more gracefully. After a long discussion, we decided we have to accept the reality that media items can have an empty source field value. They normally shouldn't, but it happens in some cases eg.:

  • The source field is not required (we strongly encourage site builders to not do this, but it is not enforced).
  • When the source field is an entity reference, the references entity can be removed (a file entity can be deleted).

In #3059950: Media sources should handle empty source field values more gracefully we improved the handling of the NULL value so we don't throw a fatal error anymore. It would be nice to add logging for media items that have this problem, so editors can easily find those media items and correct the source field value if needed.

Proposed resolution

To be determined..

Remaining tasks

Discuss if logging should be added for NULL source field values, and if we want it, how to add it.
Write patch
Review
Commit

User interface changes

None.

API changes

None.

Data model changes

None.

Release notes snippet

None.

CommentFileSizeAuthor
#13 add_logging_for_empty_source.patch710 byteskarma86

Comments

seanB created an issue. See original summary.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

chrisdarke’s picture

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

ajv009’s picture

YUp, I think we should throw a warning in watchdog, what say?
patch should be as simple as adding a logger where it identifies that its NULL gracefully :)

anjali rathod’s picture

Assigned: Unassigned » anjali rathod
anjali rathod’s picture

Should we create an event subscriber in core image module for this feature?

ajv009’s picture

Nope, that will be too much for just reporting...
Instead, you can just add a drupal watchdog logger that will report a warning somewhere here https://www.drupal.org/project/drupal/issues/3059950

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

cindytwilliams’s picture

Tagging this issue for first time contributors at DrupalCon Prague 2022.

rodrigoaguilera’s picture

Version: 9.5.x-dev » 10.1.x-dev
Assigned: anjali rathod » Unassigned
Issue tags: -Novice, -Prague2022

Doing some triaging before the Drupalcon Prague 2022 sprints for mentoring.
Since this issue still needs discussion I believe it is not a good candidate for novices.

Also un-assigning because we don't usually use the field for core issues.

This is a change that should be aimed at 10.1.x if it adds the logging.

@seanB can you name the people that are relevant for this discussion?

My opinion:
Yes there should a new log entry when an editor saves/edits a media item with an empty source.

karma86’s picture

StatusFileSize
new710 bytes

Hello everyone!

I was looking into this issue and created a patch with a solution.
I'd love some feedback, I'm a novice regarding contributions.

Thanks!

marcoscano’s picture

I wasn't active in the issue that originated this one, so I might be missing some context. Here are a few things to consider though:
- In use-case example 1 in the issue description (site-builders make the media source field non-required), I feel it is unlikely that there will be someone checking the logs to detect this, so in practice I don't see the logs being useful for this site.
- In use-case example 2 (files being deleted), the log being done during the save operation wouldn't really add much value, since if the editor is saving a media item that had the file deleted, they've hopefully selected a new file? I could see a form error message / warning being more useful here.
- When performing migrations, it might be (temporarily) expected to have media items without the source field filled up, depending on how you've configured the migration. If we include a log to watchdog for every media item being saved, this could cause more harm than good filling up the logs with noise.

To me, when a media item has no source value, regardless of the reason, it's "broken". However I would argue that in normal circumstances it doesn't get into this state after a save operation, so maybe a log message there might not be the best approach? Things that come to mind:
- A way to mark these media items as broken somehow? (A flag in views? Hijacking the media label if the user is admin? Etc.)
- A status report message indicating if the site has "broken" media items. This implies querying all media content, which could get out-of-hand in sites with lots of entities.

I acknowledge none of these are ideal or feasible, so I'm mentioning them more in the spirit of brainstorming than actually suggesting them as implementation options... :)

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.