Paragraph item (simple field) not being deleted from database

Created on 27 February 2025, 6 months ago

Problem/Motivation

Steps to reproduce

  1. Make new paragraph type with just 1 field
  2. Connect that type to content type node
  3. Fill data to node
  4. List records in VIEWs - data source paragraph, fields:ID, parent name, parent type, ...
  5. Delete one item (row) from collection connected (paragraph type) to node
  6. See VIEW again - item deleted item exists

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

1.18

Component

Miscellaneous

Created by

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

Merge Requests

Comments & Activities

  • Issue created by @marianrk
  • 🇮🇳India arunsahijpal

    Working on it.

  • Pipeline finished with Failed
    6 months ago
    Total: 324s
    #438765
  • 🇮🇳India arunsahijpal

    Hi @marianrk,
    I've added a hook_entity_update to delete the referenced paragraphs please check.
    Also @berdir please check whether this should be the part of module behaviour or not.

    Thanks,
    Arun

  • Status changed to RTBC about 1 month ago
  • 🇮🇳India divyansh.gupta Jaipur

    I was successfully able to reproduce the issue and the MR applied successfully and solved the issue where if we are deleting a row from content then it is also removed from view page,
    The changes looks good to me, thus moving this to RTBC!!

  • 🇭🇺Hungary danyg Budapest

    The query condition doesn't check the parent_id. If you have multiple node types with with many different paragraphs, you may face a big problem on a single node update. Add parent_id check to the code:

        if (!empty($referenced_paragraph_ids)) {
          $query->condition('parent_id', $entity->id());
          $query->condition('id', $referenced_paragraph_ids, 'NOT IN');
        }
    
  • 🇭🇺Hungary danyg Budapest
  • 🇭🇺Hungary danyg Budapest

    Sorry, my bad, the correct code is

          // Find all orphaned paragraphs (paragraphs that are not referenced anymore).
          $paragraph_storage = \Drupal::entityTypeManager()->getStorage('paragraph');
          $query = $paragraph_storage->getQuery()->accessCheck(FALSE);
          $query->condition('parent_id', $entity->id());
    
          if (!empty($referenced_paragraph_ids)) {
            $query->condition('id', $referenced_paragraph_ids, 'NOT IN');
          }
          $orphaned_paragraph_ids = $query->execute();
    

    The parent_id has to be checked every time, not only if $referenced_paragraph_ids is not empty. Without that, all paragraphs can be removed accidentally.

Production build 0.71.5 2024