Problem/Motivation

During module installation or config import the following error may occur if you have multiple views/autocomplete plugins:

Unexpected error during import with operation create for search_api_autocomplete.search.sg_search: Unknown search plugin with ID 'views:sg_search'

The real bug is that the static cache isn't updated when a another view is added (either by module installation or config sync).

Proposed resolution

1. Either we add a method to reset the static cache in SearchPluginDeriverBase and call that for every new view that is created

2. This may also be solved in core https://www.drupal.org/project/drupal/issues/2880682

Original summary:

After enabling and doing an export -> import of configuration with drush config-import the import runs smoothly for all items, excepts for Search API Autocomplete, where I get this error:

The import failed due for the following reasons: Unexpected error during import with operation create for search_api_autocomplete.search.search_content: Unknown type plugin with ID 'views:search_content' [25.81 sec, 131.56 MB]

Content of search_api_autocomplete.search.search_content.yml:

uuid: 0ee5f681-f8e5-4022-a253-b922416a998b
langcode: en
status: true
dependencies:
  config:
    - search_api.index.default_index
id: search_content
label: 'Search content'
index_id: default_index
suggester_settings:
  server:
    fields: {  }
suggester_weights:
  server: 0
suggester_limits: {  }
type_settings:
  'views:search_content':
    displays:
      default: true
      selected:
        - page_1
options:
  limit: 10
  min_length: 3
  show_count: false
  autosubmit: true
  submit_button_selector: ':submit'
  delay: null

Comments

ressa created an issue. See original summary.

drunken monkey’s picture

Category: Bug report » Support request
Status: Active » Fixed

Probably some module version mismatch (we're in Alpha, there are still a lot of incompatible changes), or you haven't created the "search_content" view on that site, or you need to clear the cache before doing the import.

Status: Fixed » Closed (fixed)

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

ressa’s picture

Version: 8.x-1.0-alpha3 » 8.x-1.x-dev
Component: Code » General code

I just tested an import with latest dev-releases from both Search API and Search API Autocomplete, and the config-import still fails with the above error. But for some reason search_api_autocomplete.search.search_content will get imported if I run drush config-import again, so perhaps it's a question of the order of the imported items? A chicken or egg dilemma?

drunken monkey’s picture

Component: General code » Framework
Status: Closed (fixed) » Postponed (maintainer needs more info)
StatusFileSize
new653 bytes

One problem we definitely had was the missing dependency on the view. That should now be resolved, though.
If it's still not working, this could be a caching issue? Could you try disabling caching for type plugins with the attached patch and then trying the whole import again?
(Or, alternately, send me the files you're trying to import so I can reproduce this more easily.)

drunken monkey’s picture

Issue tags: +Release blocker

If it's the caching, we want to resolve this before a stable release.

drunken monkey’s picture

Category: Support request » Bug report
ressa’s picture

Status: Postponed (maintainer needs more info) » Closed (works as designed)

You were right, it was probably the missing dependency on the view which caused the error. After re-exporting configuration with the dev-versions of the modules enabled, config-import now works like a charm, sorry about the noise. It's so great that it works, thanks for your efforts with the search modules!

The Views dependency, now present in the config-file -- the diff after a fresh config-export:

@@ -4,6 +4,9 @@ status: true
 dependencies:
   config:
     - search_api.index.default_index
+    - views.view.search_content
+  module:
+    - search_api
 id: search_content
 label: 'Search content'
 index_id: default_index
larowlan’s picture

This still happens if the view and the search are imported at the same time, I suspect stale plugin caches

larowlan’s picture

The issue is the static cache on \Drupal\search_api_autocomplete\Plugin\search_api_autocomplete\search\ViewsDeriver isn't cleared by the code in search_api_autocomplete_view_insert()

Because \Drupal\Component\Plugin\Discovery\DerivativeDiscoveryDecorator::getDeriver has a static cache - which is #2880682: Derived discovery can result in rebuilding of out of date data (e.g. Block)

ludo.r’s picture

I confirm that I had to do a drush cr to be able to import the config.

In my case it was during a full site config import on a fresh database.

ArthurAttout’s picture

The issue still appears for me, even after a drush cr.

I'm under D8.6.2, with Search Autocomplete Version: 8.x-1.1

"Unknown search plugin with ID 'views:gref_articles_search_view'" at /var/www/html/modules/search_api_autocomplete/src/Utility/PluginHelper.php line 71,

merauluka’s picture

This error also occurs for me with a fresh site installation pulling from my exported configurations. Only performing a drush cr and then reimporting clears the error.

This is running on the latest dev of Search API Autocomplete, the latest official release of Search API, and using Search API Pages for the autocomplete page.

mpp’s picture

We use drush site install with --existing-config and have 2 views with each an autocomplete. On config import we get an error for one of the autocomplete yaml's :

Unexpected error during import with operation create for search_api_autocomplete.search.sg_search: Unknown search plugin with ID 'views:sg_search'

The view is properly listed as a dependency for the autocomplete config.

After a manual install and a cim, with a drush cr the config can be imported but this wont work for us as we use drush si.

This has to be a cache issue.

mpp’s picture

Issue summary: View changes
Priority: Normal » Major
Status: Closed (works as designed) » Postponed

Re-opening this issue as it definitely is a bug.

The search_api_autocomplete SearchPluginDeriverBase has a static cache $derivatives that breaks our config import:

 [notice] Synchronized configuration: create views.view.contacts.
 [notice] Synchronized configuration: create search_api_autocomplete.search.contacts.
 [notice] Synchronized configuration: create views.view.sg_search.
 [notice] Synchronized configuration: create search_api_autocomplete.search.sg_search.
 [notice] Finalizing configuration synchronization.
In ConfigImportCommands.php line 259:

Unexpected error during import with operation create for search_api_autocomplete.search.sg_search: Unknown search plugin with ID 'views:sg_search'

On the first run of ViewsDeriver::getDerivativeDefinitions the static cache is created (for search_api_autocomplete.search.contacts) but for the second one (search_api_autocomplete.search.sg_search) it uses the static cache that doesn't know about the second view (views.view.sg_search).
The static cache isn't updated when a another view is added (either by module installation or config sync).

Updated the issue summary.

drunken monkey’s picture

Status: Postponed » Needs review
Issue tags: -Release blocker
StatusFileSize
new5.95 KB

Ah, thanks a lot for investigating and re-opening!
It indeed makes sense that the static cache would lead to errors in this case. Unfortunately, it’s not particularly easy clearing that – I think the attached patch provides the simplest and cleanest option. (But I’m open for suggestions.)

Please test/review!

borisson_’s picture

Patch overall looks solid. I have one nitpick:

  1. +++ b/src/Controller/AutocompleteController.php
    @@ -82,7 +82,7 @@ public function autocomplete(SearchInterface $search_api_autocomplete_search, Re
    -    if (!$search->status()|| !$search->hasValidIndex()) {
    +    if (!$search->status() || !$search->hasValidIndex()) {
    

    This is unrelated, but correct.

  2. +++ b/tests/src/Kernel/ViewsTest.php
    @@ -155,7 +155,7 @@ protected function collectConditions(array $conditions) {
    -   * @see search_api_autocomplete_form_views_exposed_form_alter()
    +   * @see          search_api_autocomplete_form_views_exposed_form_alter()
    

    This seems unrelated (and wrong).

drunken monkey’s picture

StatusFileSize
new525 bytes
new18.48 KB

Oops, thanks! Seems I accidentally hit TAB there while thinking a different window was focused (or something like that).

(Waiting for someone confirming that this indeed resolves the problem for them.)

ressa’s picture

Status: Needs review » Reviewed & tested by the community

Thanks @drunkenmonkey! I ran into this after adding a second search instance, and I can confirm that dev-version with the patch fixes the issue.

mpp’s picture

Sorry for the late reply, looks good!

  • drunken monkey committed c8e96ee on 8.x-1.x
    Issue #2902281 by drunken monkey, mpp, borisson_: Fixed problems with...
drunken monkey’s picture

Status: Reviewed & tested by the community » Fixed

Alright, great to hear, thanks for testing and reporting back!
Committed.
Thanks again, everyone!

ressa’s picture

Thanks, it will make importing configuration smoother, so I am glad this is fixed!

Status: Fixed » Closed (fixed)

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