Error when deleting orphaned flags

Created on 24 October 2022, about 2 years ago
Updated 8 September 2024, 4 months ago

Problem/Motivation

When using the reset option to remove all "flaggings" created for a particular flag, I am getting the following PHP type error:

TypeError: Argument 1 passed to Drupal\flag\FlagCountManager::resetLoadedCounts() must implement interface Drupal\Core\Entity\EntityInterface, null given, called in /var/www/html/web/modules/contrib/flag/src/FlagCountManager.php on line 246 in Drupal\flag\FlagCountManager->resetLoadedCounts() (line 313 of /var/www/html/web/modules/contrib/flag/src/FlagCountManager.php)

I believe this error occurs when the resetLoadedCounts() method attempts to process an orphaned flag, where the related flaggable entity has been deleted.

Steps to reproduce

  1. Create a flag.
  2. Flag an entity with the flag.
  3. Delete the flagged entity.
  4. Use the Reset feature provided for the flag to delete all "flaggings" created for the flag.

Proposed resolution

Check to ensure the parent entity exists before attempting to call the resetLoadedCounts() method, which requires a valid entity object.

Remaining tasks

Create a patch to address this issue.

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Fixed

Component

Flag core

Created by

🇨🇦Canada gturnbull

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

Comments & Activities

Not all content is available!

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

Production build 0.71.5 2024