You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Attempting to delete a user in the CMS results in a flash message "Couldn’t delete the user." with nothing in the logs. This is the same whichever options is selected for the "What do you want to do with their content?" prompt.
There may be an issue specific to the environment this is happening in, but the real issue here is that nothing is in the logs due to the code block starting:
if (!Craft::$app->getElements()->deleteElement($user)) {
It (reasonably) sets a generic message for the front end and returns null. However, there should be a reason to be revealed with a call to $user->getErrors() within this if block. It would be great if those reason(s) were logged so I can see what went wrong.
Steps to reproduce
Add a user
[Somehow break something so the user fails to delete]
Attempt to delete the user
Expected behavior
User deleted or if not deleted, there should be a way to find out why. I am not advocating showing the error on the front-end of course.
Actual behavior
Error as above, nothing logged. In my specific case, If I add a call to $user->getErrors() within the relevant block, it returns an empty array, which is a little strange considering Craft::$app->getElements()->deleteElement($user) returned false and no exceptions were thrown.
Craft CMS version
4.3.7.1 (but the relevant code is the same on the HEAD of develop)
PHP version
N/A
Operating system and version
N/A
Database type and version
N/A
Image driver and version
N/A
Installed plugins and versions
Commerce 4.2.5.1
The text was updated successfully, but these errors were encountered:
For my specific case (although maybe not directly related to the primary drive of this issue):
Browsing through the code, whatever is causing this is probably happening within craft\elements\User::beforeDelete() - more than likely one of our custom fields in it's beforeElementDelete() method or EVENT_BEFORE_ELEMENT_DELETE event.
When I say custom fields, having double checked it's only a single addresses field (via Commerce plugin). Everything else is just standard built in user fields.
Hi, thanks for reaching out. This could be a duplicate of: #13100. Does the user you’re trying to delete have any commerce orders associated with them?
If #13100 is saying that the fix to the "showing success while actually an error" problem was to show the error in the title of this issue, then I guess this will have to wait until a more specific error can be shown (or probably better: logged somewhere as it could be sensitive to show in the front-end).
What happened?
Description
Attempting to delete a user in the CMS results in a flash message "Couldn’t delete the user." with nothing in the logs. This is the same whichever options is selected for the "What do you want to do with their content?" prompt.
There may be an issue specific to the environment this is happening in, but the real issue here is that nothing is in the logs due to the code block starting:
cms/src/controllers/UsersController.php
Line 1938 in 2039956
It (reasonably) sets a generic message for the front end and returns
null
. However, there should be a reason to be revealed with a call to$user->getErrors()
within thisif
block. It would be great if those reason(s) were logged so I can see what went wrong.Steps to reproduce
Expected behavior
User deleted or if not deleted, there should be a way to find out why. I am not advocating showing the error on the front-end of course.
Actual behavior
Error as above, nothing logged. In my specific case, If I add a call to
$user->getErrors()
within the relevant block, it returns an empty array, which is a little strange consideringCraft::$app->getElements()->deleteElement($user)
returnedfalse
and no exceptions were thrown.Craft CMS version
4.3.7.1 (but the relevant code is the same on the HEAD of develop)
PHP version
N/A
Operating system and version
N/A
Database type and version
N/A
Image driver and version
N/A
Installed plugins and versions
Commerce 4.2.5.1
The text was updated successfully, but these errors were encountered: