Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.x]: "Couldn’t delete the user." when deleting a user #13290

Closed
rob-baker-ar opened this issue Jun 7, 2023 · 4 comments
Closed

[4.x]: "Couldn’t delete the user." when deleting a user #13290

rob-baker-ar opened this issue Jun 7, 2023 · 4 comments

Comments

@rob-baker-ar
Copy link

rob-baker-ar commented Jun 7, 2023

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:

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

  1. Add a user
  2. [Somehow break something so the user fails to delete]
  3. 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

@rob-baker-ar
Copy link
Author

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.

@i-just
Copy link
Contributor

i-just commented Jun 7, 2023

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?

@rob-baker-ar
Copy link
Author

[deleted previous comment]

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).

@i-just
Copy link
Contributor

i-just commented Jun 7, 2023

Just did a quick test, and as of Commerce 4.2.10, the stopgap solution has been implemented: craftcms/commerce#3071

Screenshot 2023-06-07 at 13 51 24

Hope this helps!

@i-just i-just closed this as completed Jun 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants