Enforced dependency bundles are deleted without validation when modules are uninstalled

Created on 15 December 2023, about 1 year ago
Updated 27 February 2024, 10 months ago

Problem/Motivation

I discovered this with a site that had uninstalled forum module, but I think it's a generic entity issue. Opening as critical because it's data loss, and reproducible 100% via the UI with core.

Steps to reproduce

1. Install the standard profile
2. Create a new 'discussions' node type
3. Re-use the 'comment_forum' comments field.
4. Create a discussion.
5. Comment on the discussion
6. Delete any terms in the forums vocabulary (because you won't be able to uninstall unless you do)
7. Uninstall forum module
8. SELECT * FROM comment_field_data; - the comment is still there
9. SELECT * FROM comment__comment_body; - the comment body is still in the database for now, but it's been marked as deleted.
10. Browse to comment/1 You will get Error: Call to a member function getSetting() on null in Drupal\comment\Controller\CommentController->commentPermalink() (line 129 of core/modules/comment/src/Controller/CommentController.php

However if you install forum, post a comment, then try to delete the comment_forum bundle, you get this in the UI:

Comment_forum is used by the node.comment_forum field on your site. You can not remove this comment type until you have removed the field.

Comment_forum is used by 1 comment on your site. You can not remove this comment type until you have removed all of the Comment_forum comments.

Proposed resolution

Not sure yet. We should not allow deleting bundles when there is content for that bundle in the database, so maybe adding this to validation, which would then prevent uninstall until the entities are deleted (similar to what is already done with taxonomy terms) would work. Then it wouldn't matter that we also delete the fields associated with the bundles and you wouldn't end up with invalid entities in the database.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

πŸ› Bug report
Status

Active

Version

11.0 πŸ”₯

Component
Configuration entityΒ  β†’

Last updated 2 days ago

Created by

πŸ‡¬πŸ‡§United Kingdom catch

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

Comments & Activities

  • Issue created by @catch
  • πŸ‡¬πŸ‡§United Kingdom catch
  • πŸ‡¬πŸ‡§United Kingdom catch

    Extra info, there is custom validation in Forum module, ForumUninstallValidator that prevents the module from being uninstalled if there are any forum nodes or forum terms in the database.

    However if you re-use the comment_forum field, then you can have comments on different entity types that won't be uninstalled by forum, and forum doesn't check for comment_forum comments in its validator.

    Seems like a general bundle entity deletion validator would be better than any of the custom stuff.

    The validation that comment module does when you attempt to delete an in-use comment bundle is also only done for the form, not at the config entity level.

  • First commit to issue fork.
Production build 0.71.5 2024