When entity is deleted TypeError is thrown

Created on 4 July 2018, over 6 years ago
Updated 19 October 2024, about 1 month ago

We're using the flag module as a favorite function. We use AJAX type flags. When a entity gets deleted and then a flag is still added, it will throw a fatal TypeError (see below). Of course, the entity shouldn't be flagged in the first place, but is still possible for people that are:

1. Seeing a entity on a page that they loaded before it was deleted.
2. Seeing a entity that is somehow still on a page due to caching. (this is rather poor caching then a flagging problem, but still)

TypeError: Argument 2 passed to Drupal\flag\FlagService::flag() must implement interface Drupal\Core\Entity\EntityInterface, null given, called in /my/project/web/modules/contrib/flag/src/Controller/ActionLinkController.php on line 77 in Drupal\flag\FlagService->flag() (line 252 of modules/contrib/flag/src/FlagService.php).
Drupal\flag\FlagService->flag(Object, NULL) (Line: 77)
Drupal\flag\Controller\ActionLinkController->flag(Object, '436', Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 582)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 151)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 99)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 78)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 666)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
🐛 Bug report
Status

Needs work

Version

4.0

Component

Flag core

Created by

🇳🇱Netherlands aken.niels@gmail.com

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

    The patch will have to be re-rolled with new suggestions/changes described in the comments in the issue.

  • 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

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