Mandatory parameters missing

Created on 25 February 2025, 2 months ago

Problem/Motivation

With latest version (beta20) I am getting the following error when trying to delete a Group (from `groups` module).

The website encountered an unexpected error. Try again later.

Drupal\Core\Entity\EntityStorageException: Some mandatory parameters are missing ("group") to generate a URL for route "entity.group_content_menu.canonical". in Drupal\Core\Entity\Sql\SqlContentEntityStorage->delete() (line 763 of core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).

Drupal\Core\Routing\UrlGenerator->getInternalPathFromRoute() (Line: 300)
Drupal\Core\Routing\UrlGenerator->generateFromRoute() (Line: 108)
Drupal\Core\Render\MetadataBubblingUrlGenerator->generateFromRoute() (Line: 765)
Drupal\Core\Url->toString() (Line: 41)
Drupal\entity_usage\PreSaveUrlRecorder->recordEntity() (Line: 43)
entity_usage_entity_presave()
call_user_func_array() (Line: 416)
Drupal\Core\Extension\ModuleHandler->Drupal\Core\Extension\{closure}() (Line: 395)
Drupal\Core\Extension\ModuleHandler->invokeAllWith() (Line: 415)
Drupal\Core\Extension\ModuleHandler->invokeAll() (Line: 217)
Drupal\Core\Entity\EntityStorageBase->invokeHook() (Line: 900)
Drupal\Core\Entity\ContentEntityStorageBase->invokeHook() (Line: 529)
Drupal\Core\Entity\EntityStorageBase->doPreSave() (Line: 753)
Drupal\Core\Entity\ContentEntityStorageBase->doPreSave() (Line: 483)
Drupal\Core\Entity\EntityStorageBase->save() (Line: 806)
Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (Line: 354)
Drupal\Core\Entity\EntityBase->save() (Line: 303)
Drupal\group\Entity\GroupRelationship::postDelete() (Line: 460)
Drupal\Core\Entity\EntityStorageBase->delete() (Line: 753)
Drupal\Core\Entity\Sql\SqlContentEntityStorage->delete() (Line: 362)
Drupal\Core\Entity\EntityBase->delete() (Line: 383)
Drupal\group\Entity\Group::preDelete() (Line: 450)
Drupal\Core\Entity\EntityStorageBase->delete() (Line: 753)
Drupal\Core\Entity\Sql\SqlContentEntityStorage->delete() (Line: 362)
Drupal\Core\Entity\EntityBase->delete() (Line: 71)
Drupal\Core\Entity\ContentEntityDeleteForm->submitForm()
call_user_func_array() (Line: 129)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers() (Line: 67)
Drupal\Core\Form\FormSubmitter->doSubmitForm() (Line: 597)
Drupal\Core\Form\FormBuilder->processForm() (Line: 326)
Drupal\Core\Form\FormBuilder->buildForm() (Line: 73)
Drupal\Core\Controller\FormController->getContentResult() (Line: 39)
Drupal\layout_builder\Controller\LayoutBuilderHtmlEntityFormController->getContentResult()
call_user_func_array() (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 638)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 121)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 181)
Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 53)
Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle() (Line: 32)
Drupal\big_pipe\StackMiddleware\ContentLength->handle() (Line: 116)
Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 90)
Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 36)
Drupal\Core\StackMiddleware\AjaxPageState->handle() (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 741)
Drupal\Core\DrupalKernel->handle() (Line: 19)

The error doesn't happen with beta19.
I updated from beta16 to beta20 when I found out about this.

Steps to reproduce

Still collection information, but adding and trying to delete a group seems to be enough.

πŸ› Bug report
Status

Active

Component

Code

Created by

πŸ‡¬πŸ‡·Greece bserem

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

Merge Requests

Comments & Activities

  • Issue created by @bserem
  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    So this is an entity type where $entity->toUrl() is broken - that is quite interesting. Looking at https://git.drupalcode.org/project/group_content_menu/-/blob/3.0.x/src/E... it looks like the entity that is causing this is quite broken. It's tricky to know what to do here. We can change

        try {
          $this->urls[$this->key($entity)] = $entity->toUrl()->toString();
        }
        catch (EntityMalformedException | UndefinedLinkTemplateException) {
          // If we cannot create a URL then there is no URL to record.
        }
    

    to catch more generic exceptions to work around broken entities but I think the correct thing here is for the group_content_menu to throw an EntityMalformedException exception. So I'm going to move this issue to that module and do that change.

  • Merge request !48Fix toUrl exception β†’ (Merged) created by alexpott
  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ
  • Pipeline finished with Failed
    2 months ago
    Total: 220s
    #434418
  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    The funny thing about this is that the entity being saved here is going to be deleted when

    /**
     * Implements hook_ENTITY_TYPE_delete().
     */
    function group_content_menu_group_delete(EntityInterface $entity) {
      // Remove the group menu and recursively its links on group deletion.
      foreach (group_content_menu_get_menus_per_group($entity) as $group_relationship) {
        $group_relationship->getEntity()->delete();
      }
    }
    

    runs...

    So the save is a complete waste of energy...

    That said this change is still correct - we should emit the correct exception at this point.

  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    Potentially πŸ“Œ Plugin config: Delete entity along with GroupContent Needs review would help with #5 - but as said there I think this fix is worth it in its own right.

  • Pipeline finished with Skipped
    2 months ago
    #434661
  • First commit to issue fork.
  • heddn Nicaragua

    Always helpful with a test.

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024