Viewing and editing orphaned comments results in a fatal error

Created on 21 January 2022, almost 3 years ago
Updated 4 February 2023, almost 2 years ago

Problem/Motivation

Viewing and editing orphaned comments results in a fatal error. getCommentedEntity() returns NULL on non existing entities. As follow up to https://www.drupal.org/project/drupal/issues/2614720 it's still possible to trigger fatal errors for example when viewing orphaned comments.

Steps to reproduce

Create a comment and manually delete the referenced entity.
Viewing the comment will result in a fatal error

Proposed resolution

Add extra checks

Remaining tasks

Add tests?

User interface changes

None

API changes

None

Data model changes

None

Release notes snippet

🐛 Bug report
Status

Postponed: needs info

Version

10.1

Component
Comment 

Last updated 11 days ago

Created by

🇳🇱Netherlands Rhezios

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇺🇸United States smustgrave

    This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.

    I tried replicating on D10 and instead of a fatal error I get a 404. Could someone else confirm?

    Moving to PNMI but if still an issue move to needs work as this will need test to show the issue.

  • Status changed to Closed: outdated 10 months ago
  • 🇺🇸United States smustgrave

    Since there hasn't been a follow up going to close for now. If still a valid bug please reopen

  • First commit to issue fork.
  • Merge request !9583Add checks if commented entity actually exists → (Open) created by casey
  • 🇳🇱Netherlands casey

    Snapshot of latest state of MR for usage with composer patches on drupal/core:10.3.*

  • Pipeline finished with Success
    3 months ago
    Total: 593s
    #290442
  • 🇺🇸United States smustgrave

    Will still need test coverage.

    Issue summary should probably be updated too. "Add extra check" isn't a complete solution I'd say.

  • 🇮🇳India arunkumark Coimbatore

    I verified the issue, unable to replicate. Below are the steps I followed to replicate the issue.

    Scenario 1: Attached Entity removed
    1. Added Comment to Article content type.
    2. Created node, and added Comment to Node.
    3. Added child comments to the parent comment.
    4. Deleted Node programmatically using below script,

    $nodeStorage = \Drupal::service('entity_type.manager')->getStorage('node');
    $node = $nodeStorage->load(NID);
    $node->delete();

    5. Accessed the Comment Edit and Delete URLs.
    6. Getting page not found page instead of Error.

    Scenario 2: Attached Parent comment removed
    1. Added Comment to Article content type.
    2. Created node, and added Comment to Node.
    3. Added child comments to the parent comment.
    4. Deleted Parent Comment programmatically using the below script,

    $commentStorage = \Drupal::service('entity_type.manager')->getStorage('comment');
    $comment = $commentStorage->load(CID);
    $comment->delete();

    5. Accessed the Child Comment Edit and Delete URLs.
    6. Getting page not found page instead of Error.

Production build 0.71.5 2024