Closed (duplicate)
Project:
Drupal core
Version:
9.3.x-dev
Component:
media system
Priority:
Major
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
24 May 2019 at 19:33 UTC
Updated:
10 Apr 2022 at 10:48 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
olivier.bouwman commentedThis code is copied from Node preSave https://git.drupalcode.org/project/drupal/blob/8.8.x/core/modules/node/s...
Comment #3
ashleyhazle commentedWe have seen this when creating new media entities, after updating to 8.7.x (currently on 8.7.2).
Whilst this patch makes sense in the context of a user having been deleted, we find that an author is no longer automatically added when creating media.
Equally, the UID should really be updated when the user account is deleted.
I get that this is taken from Node preSave, but it feels like it's just working around a larger problem.
Comment #4
jcnventuraOur case is we're using paragraphs with entity references to media entities. When saving the article, we get the same exception being thrown. Adding this patch fixes the issue. No clue why we're saving the media when adding entity references to it.
This site was previously using the media_entity module, but we've upgraded to media-in-core.
This was working fine with core 8.6.14, and after updating to core 8.7.2, we started to get this error. Updating to core 8.7.3 did not fix it.
Comment #5
init90The same approach was used in Drupal Commerce to fix similar error:
https://www.drupal.org/project/commerce/issues/3020240
Comment #6
spokjeI'm experiencing the exact same as jcnventura in #4, so Paragraphs with entity references to media entities.
Patch #2 does fix the immediate issue, but in my (and jcnventura's) case it seems wrong to set the owner of the media to
Anonymous, since in our case, we have an actual owner.Due to that (and the fact that we never going to get this in without tests) setting it back to
Needs Work, but again stressing the patch _does_ fix the immediate issue and will allow Media to be saved.I hope to get back later today and at least write some tests, but if somebody beats me to that, I would be very grateful.
Leaving this at
Majorsince it involves lost user input.Comment #7
spokjeRight...the motto 'Think before you type' applies once again.
Just after submitting the above I realized the Root Cause for sites coming from
drupal/media_entity, which lies here: https://www.drupal.org/project/media_entity/issues/2953384#comment-12557186A telltale sign that the error is caused by a
drupal/media_entityto Core Media migration is the presence of this PHP Warning just before the actual fatal Error:Warning: call_user_func() expects parameter 1 to be a valid callback, class 'Drupal\media_entity\Entity\Media' not found in Drupal\Core\Field\FieldConfigBase->getDefaultValue() (line 397 of \web\core\lib\Drupal\Core\Field\FieldConfigBase.php@jcnventura Could you search your exported config for
default_value_callback: 'Drupal\media_entity\Entity\Media::getCurrentUserId', replace that withdefault_value_callback: 'Drupal\media\Entity\Media::getCurrentUserId', import the changed config and remove the patch in #2?That worked out all fine for me, and now the newly added media will have the correct UserID attached, instead of
Anonymousas it would be the case with this patch.@ashleyhazle: Due to your comment
it seems to me that your site also has transitioned from
drupal/media_entityto Core Media and all your current media is/was having an invalidNULLasuiddue to the above (the callback to the non-existingmedia_entitymodule).That would explain all your media ending up needing patch #2 for saving, but with that patch assigning the anonymous
uid0 to them.If either/both of you are still following this issue and could confirm the above, that would be grand.
So currently the only case for this error to happens seems to be when a User is deleted, but its content is not deleted and not assigned to the anonymous user.
As far as I can think of, that's only possible if the user is deleted programmatically, so this issue might not be a priority Major after all, since it doesn't affect loads of people. I'll let smarter people than me decide on that.
For my penance I'll come back later and write a test for the above. :)
Comment #8
spokjeComment #9
phenaproximaThis might be a duplicate of #3043725: Provide a Entity Handler for user cancelation.
Comment #10
spokje@phenaproxima It most definitely is IMHO.
EDIT: Aaand I stand corrected: This issue is a very specific edge case that ist covered in patch #2 in the related issue.
Steps to reproduce:
- D8.7.x, enabled Media.
- Create user
- Login with that user
- Create a Media Item
- Delete that user
in a nasty programmatically way (I used `devel_php`);- Login with another user.
- Try to save Media item through Admin GUI
- CLUNK
Since the mentioned patch in the other issue implements a
media_user_predeletewhich deletes all media entities and revisions owned by the user that is getting deleted, the CLUNK part won't happen, since you can't edit non-existing (since already deleted) media entities.If the deletion is a good thing is debatable, but it _is_ consistent with all (rather most until the parent issue is fixed) other entities owned by the deleted user, they are also deleted.
Comment #11
spokjeEDIT: Stand corrected again.
Deleting a Media owning user through the Admin GUI is already triggering this error.
Steps to reproduce:
- D8.7.x, enabled Media.
- Create user
- Login with that user
- Create a Media Item
- Delete that user.
- Login with another user.
- Try to save Media item through Admin GUI
- CLUNK
Comment #12
anas_maw commentedPatch in #2 fixed my issue.
Comment #14
spokjeComment #15
mohit_aghera commentedComment #16
nikunjkotechaAfter discussion with Mohit and Jitesh we found out that the root cause was the missing implementation of hook_user_cancel() only and we should go ahead with implementation of it. Mohit is working on tests for same.
Comment #17
liampower commentedPatch in #2 fixed the fatal error on saving, this is similar to how nodes work if you remove the author.
The patch in #16 is covered by the related issue #3069291 and I believe further work for media items when users are deleted should be done there.
Comment #18
droodpal commentedHi, very similar problem, when trying to create native article or a basic page. Other content types work. I've posted details here:
https://drupal.stackexchange.com/questions/294562/cant-create-an-article...
Any ideas what causes it?
Other Content Types, when Warnings enabled show:
Reinstall didn't help, cache cleaning, update.php - tried all.
Comment #19
norwegian.blue commentedI am also seeing this issue on D9.0.1.
The site I am experiencing the issue in did not previously use media - either contrib or core.
The main issue I experience is one that seems to have been mostly ignored from #3 .
When creating media, if no author is specified manually, then this exception is thrown. Manually specifying the author allows the media item to be created.
This appears to have the add-on effect of not allowing media to be created from the library interface.
Comment #20
norwegian.blue commentedUpdate.
I've resolved my issue.
2953384 #4 gave me the clue to resolving this for me.
When I inspected core.base_field_override.media.image.uid.yml exported from my site, it appeared correct. Another site not experiencing this issue did not have that config file exported.
I deleted all .yml's that overide the base field uid (eg core.base_field_override.media.image.uid.yml ,core.base_field_override.media.video.uid.yml )
and reimported the config (drush config:import sync)
This resolved the issue for me.
Environment:
PHP7.3
Drupal 9.0.1
MySQL
Linux
Apache
NOTE - I was also experiencing the same issue as #18 . Deleting the config that overrides the uid field for the affected content types also resolved this.
Comment #21
tanubansal commentedPlease check the attached Screenshot of issue that i got in 9.1. Is there any patch available for 9.1?
Comment #22
dwwRe: "Is there any patch available for 9.1?" -- Both #2 and #16 apply cleanly to the 9.1.x branch. You could have tried that yourself.
Hiding screenshots from the file table in the summary -- we only need to see patches there.
Haven't fully wrapped my head around this issue and given thought to the right way to actually fix it. Patch #16 here is extremely similar to #3069291-2: Quick win: Media entities support user cancel (which was posted 6 months prior), since both are basically just copy/paste renames of
node_mass_update()tomedia_mass_update()(more or less).Tagging this for a subsystem maintainer review, since it seems like both this and #3069291: Quick win: Media entities support user cancel should be closed as duplicates with #3043725: Provide a Entity Handler for user cancelation, but that's not up to me. ;)
p.s. I moved to "Needs work" for tests, but that's already further along at both of the other issues...
Comment #23
phenaproximaI think I agree with @dww. This would be solved by #3043725: Provide a Entity Handler for user cancelation, so we should concentrate our efforts there.
Comment #24
danrodI can confirm that patch #2 works for the 9.2.x branch.
Comment #25
scot.hubbard commentedI started experiencing this with a Drupal 9 site (not sure when it began, but I have latest 9.2 core installed now).
For me, the fix was to look at the core.base_field_override.media.--MEDIA_TYPE--.uid.yml files, and change the following line:
default_value_callback: 'Drupal\media\Entity\Media::getCurrentUserId'
to this:
default_value_callback: 'Drupal\media\Entity\Media::getDefaultEntityOwner'
Once re-imported, there are no log entries for "call_user_func" and when adding new media items, the author field defaults to the current user.
Comment #26
nicolas s. commentedI confirm that patch #2 works for the 9.1.x branch.
Comment #27
aleksi_anisimov commentedWhy do you use "0" as default value, instead of current user id, if it's set?
Would it be more logical to user current user id?
Comment #28
amitajgaonkar commented#25 worked for me
Comment #29
edward.peters commented#25 worked for me too. Thank you for the help.
Comment #30
srihari manepally commentedI have modified the patch so that it takes current user id instead of "0"(anonymous user). This patch worked on Drupal 9.2.7 version.
Comment #31
heyehren commentedHi there,
I'm experiencing the same error message when trying to create a new media file on the 'Add media item' page (/media/add).
This is the error message:
TypeError: call_user_func(): Argument #1 ($callback) must be a valid callback, class "Drupal\media_entity\Entity\Media" not found in call_user_func() (line 398 of core/lib/Drupal/Core/Field/FieldConfigBase.php).Originally i migrated from the media module to media core, and everything worked well until a recent upgrade to Drupal 9.
I have applied patch 2, which didn't work for me. Then i tried patch 30, which also didn't make a difference.
Does the patch have to be altered to work with Drupal 9.3.9?
I'd also like to try the suggestion in #25, but i don't know how to re-import the file after it has been altered.
Any help with this would be greatly appreciated.