Exception thrown when creating a Finder

Created on 17 January 2025, 3 months ago

When creating a finder using a new "Events channel" content type and the existing "Event" type from localgov_events, I get an exception thrown on submit:

The website encountered an unexpected error. Try again later.

Drupal\search_api\SearchApiException: The "date_recur:node__finders_events_date" plugin does not exist. Valid plugin IDs for Drupal\search_api\Datasource\DatasourcePluginManager are: date_recur:node__localgov_event_date, entity:block_content, entity:content_moderation_state, entity:crop, entity:file, entity:geo_entity, entity:ofsted_registration, entity:localgov_alert_banner, entity:localgov_directories_facets, entity:localgov_geo, entity:review_date, entity:media, entity:menu_link_content, entity:node, entity:paragraphs_library_item, entity:path_alias, entity:preview_link, entity:radioactivity, entity:redirect, entity:scheduled_transition, entity:search_api_task, entity:taxonomy_term, entity:user, entity:webform_submission, entity:paragraph in Drupal\search_api\Utility\PluginHelper->createIndexPlugin() (line 81 of modules/contrib/search_api/src/Utility/PluginHelper.php).
Drupal\Core\Plugin\DefaultPluginManager->getDefinition() (Line: 16)
Drupal\Core\Plugin\Factory\ContainerFactory->createInstance() (Line: 83)
Drupal\Component\Plugin\PluginManagerBase->createInstance() (Line: 78)
Drupal\search_api\Utility\PluginHelper->createIndexPlugin() (Line: 130)
Drupal\search_api\Utility\PluginHelper->createDatasourcePlugin() (Line: 469)
Drupal\finders\Plugin\FinderType\FinderTypeBase->getIndexDatasource() (Line: 185)
Drupal\finders\Plugin\FinderType\FinderTypeBase->alterSearchIndex() (Line: 258)
Drupal\finders\FinderConfigManager->ensureFinderConfig() (Line: 231)
Drupal\finders\Entity\Finder->postSave() (Line: 563)
Drupal\Core\Entity\EntityStorageBase->doPostSave() (Line: 489)
Drupal\Core\Entity\EntityStorageBase->save() (Line: 257)
Drupal\Core\Config\Entity\ConfigEntityStorage->save() (Line: 354)
Drupal\Core\Entity\EntityBase->save() (Line: 614)
Drupal\Core\Config\Entity\ConfigEntityBase->save() (Line: 293)
Drupal\Core\Entity\EntityForm->save() (Line: 289)
Drupal\finders\Form\FinderForm->save()
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()
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: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 85)
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: 23)

This can be fixed by calling this at the end of \Drupal\finders\FinderConfigManager::configureAsEntry():

\Drupal::service('cache.discovery')->invalidateAll();

I'll make a PR to inject this and call it properly. I spotted when looking at the code that it doesn't use constructor property promotion. Is there a reason for that? It'd save a *load* of boilerplate on a class with this many dependencies.

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇬🇧United Kingdom rupertj Bristol, UK

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

Merge Requests

Comments & Activities

  • Issue created by @rupertj
  • 🇬🇧United Kingdom joachim

    > I spotted when looking at the code that it doesn't use constructor property promotion. Is there a reason for that?

    That's not in the Drupal coding standards yet AFAIK.

    I use DCB for generating DI code, so the the boilerplate isn't a problem to write at least!

    > \Drupal::service('cache.discovery')->invalidateAll();

    I wonder why the tests don't crash too?

  • 🇬🇧United Kingdom rupertj Bristol, UK

    From the core discussion ( https://www.drupal.org/project/drupal/issues/3278431 📌 Use PHP 8 constructor property promotion for existing code Needs work ) I took that using constructor property promotion should be encouraged for new code. LGD's code uses it for most classes already.

  • 🇳🇱Netherlands ekes

    > I took that using constructor property promotion should be encouraged for new code

    +1 for that interpretation. We did already make that assumption in LGD code; plus imho it's soooooo much nicer.

  • 🇬🇧United Kingdom rupertj Bristol, UK
  • 🇬🇧United Kingdom rupertj Bristol, UK

    I'm also getting this exact error when trying to create a finder from a module's install config. The change in my PR doesn't help in that case though, so I'm thinking it might not be the correct fix.

  • 🇬🇧United Kingdom joachim

    > Drupal\search_api\SearchApiException: The "date_recur:node__finders_events_date" plugin does not exist. Valid plugin IDs for Drupal\search_api\Datasource\DatasourcePluginManager

    I think it might help to draw up a hierarchy of plugin dependencies.

    The datasource is derived from the existence of the date_recur field which IIRC the events Finder type plugin will have defined.

    Can you debug in DateRecurDatasourceDeriver to see why it's not seen at that point?

  • 🇬🇧United Kingdom rupertj Bristol, UK

    Ta. That was helpful.

    I've figured out that the date_recur field doesn't exist because in Finder::ensureFinderConfig(), getEntryBundles() returns an empty array and then configureAsEntry() isn't called.

    Stepping through, it seems that when the entity type is loaded, it's not found. Either this is some cache thing, or the entity type genuinely doesn't exist yet. This is a possibility as that's being created in this same config import.

  • 🇬🇧United Kingdom joachim

    I can't remember how much work I did on declaring config dependencies, but it's quite likely I was a bit lax about it. If those are in place, Drupal's config install system will know what to install in what order.

    On the other hand, 3rd party should be allowed to add config dependencies Active aaaargh.

  • 🇬🇧United Kingdom rupertj Bristol, UK

    Adding a couple of dependencies for the content types for my exported finder fixes this issue:

    langcode: en
    status: true
    dependencies:
      module:
        - finders_events
      config:
        - node.type.localgov_event
        - node.type.localgov_event_channel
    id: localgov_events
    label: 'LocalGov Events'
    type: events
    channels:
      node:
        - localgov_event_channel
    entries:
      node:
        - localgov_event
    

    I get another error later in the install process but I'm not sure if it's related yet.

  • 🇬🇧United Kingdom joachim

    That's promising!

    The Finder entity class needs to implement calculateDependencies() to declare these.

  • 🇬🇧United Kingdom joachim

    Maybe need an issue at date_recur_search_api to do the same to Drupal\date_recur_search_api\Plugin\search_api\datasource\DateRecur

    .

  • 🇬🇧United Kingdom joachim
  • 🇬🇧United Kingdom joachim

    @rupertj Could you try this MR please?

  • 🇬🇧United Kingdom rupertj Bristol, UK

    This looks good to me. With the patch applied and the finder re-saved and exported, I get the same dependencies that I manually inserted.

  • Pipeline finished with Skipped
    2 months ago
    #424161
    • joachim committed 67fea807 on 1.0.x
      Issue #3500599 by rupertj, joachim: Fixed finder entity not declaring...
  • 🇬🇧United Kingdom joachim

    Thanks!

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

Production build 0.71.5 2024