After I delete a piece of content with paragraph data, the paragraph data is still visible in the database.

Issue fork paragraphs-2935630

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

paul_canning created an issue. See original summary.

miro_dietiker’s picture

Status: Active » Closed (works as designed)

If you delete content (as in deleting the node), the paragraph is deleted. I just tested this with most recent versions.

However, deleting a Paragraph only (not the node) doesn't result in deleting it. There are multiple issues about this in Paragraphs and Entity Reference Revisions, mainly around the subject of garbage collection.

zorax’s picture

I confirm, in database, information are not removed in :
paragraphs_item_field_data
paragraphs_item_revision
paragraphs_item_revision_field_data

On all the field value too :
paragraph_revision__field_X
paragraph__field_X

data are not deleted even if you delete the node.
version :8.x-1.12

karimbou’s picture

Having this issue to this date, in my content node, even removing paragraphs doesn't affect a view that list those paragraphs based on it's node ....
D8.9.20 everything uptodate.

hcanning’s picture

Was there ever a solution? Same issue Drupal 10.4.0 and Paragraphs 8.x-1.18 - when node is deleted the paragraph field value remains in db

jkingsnorth’s picture

Version: 8.x-1.x-dev » 8.x-1.20
Priority: Critical » Major
Status: Closed (works as designed) » Active

I'm also experiencing this issue with 8.x-1.20 and Drupal 11.3

When deleting a node, the paragraph items attached to it remain at least in the paragraphs_item / paragraphs_item_data tables

yashaswi18’s picture

I looked into this issue and worked on a possible approach to clean up referenced paragraph entities when the parent entity is deleted.
I implemented the following in paragraphs.module:

function paragraphs_entity_delete(EntityInterface $entity) {
  $storage = \Drupal::entityTypeManager()->getStorage('paragraph');

  foreach ($entity->getFieldDefinitions() as $field_name => $definition) {
    if ( $definition->getType() !== 'entity_reference_revisions' || $definition->getSetting('target_type') !== 'paragraph') {
      continue;
    }

    foreach ($entity->get($field_name) as $item) {
      if ($paragraph = $storage->load($item->target_id)) {
        $paragraph->delete();
      }
    }
  }
}

I tested this locally by creating content with paragraph references, deleting the parent node, and verifying that the related paragraph records were removed from the paragraph tables in the database.
Sharing this approach here for review and feedback in case it helps move the issue forward.

benstallings’s picture

Version: 8.x-1.20 » 8.x-1.x-dev
Assigned: Unassigned » benstallings

benstallings’s picture

Assigned: benstallings » Unassigned
Status: Active » Needs review