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