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| Comment | File | Size | Author |
|---|---|---|---|
| #18 | 2902281-18--clear_static_derivative_caches.patch | 18.48 KB | drunken monkey |
Comments
Comment #2
drunken monkeyProbably 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.
Comment #4
ressaI 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-importagain, so perhaps it's a question of the order of the imported items? A chicken or egg dilemma?Comment #5
drunken monkeyOne 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.)
Comment #6
drunken monkeyIf it's the caching, we want to resolve this before a stable release.
Comment #7
drunken monkeyComment #8
ressaYou 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:
Comment #9
larowlanThis still happens if the view and the search are imported at the same time, I suspect stale plugin caches
Comment #10
larowlanThe 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)
Comment #11
ludo.rI confirm that I had to do a
drush crto be able to import the config.In my case it was during a full site config import on a fresh database.
Comment #12
ArthurAttout commentedThe 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,Comment #13
merauluka commentedThis error also occurs for me with a fresh site installation pulling from my exported configurations. Only performing a
drush crand 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.
Comment #14
mpp commentedWe use drush site install with
--existing-configand 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.
Comment #15
mpp commentedRe-opening this issue as it definitely is a bug.
The search_api_autocomplete SearchPluginDeriverBase has a static cache $derivatives that breaks our config import:
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.
Comment #16
drunken monkeyAh, 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!
Comment #17
borisson_Patch overall looks solid. I have one nitpick:
This is unrelated, but correct.
This seems unrelated (and wrong).
Comment #18
drunken monkeyOops, 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.)
Comment #19
ressaThanks @drunkenmonkey! I ran into this after adding a second search instance, and I can confirm that dev-version with the patch fixes the issue.
Comment #20
mpp commentedSorry for the late reply, looks good!
Comment #22
drunken monkeyAlright, great to hear, thanks for testing and reporting back!
Committed.
Thanks again, everyone!
Comment #23
ressaThanks, it will make importing configuration smoother, so I am glad this is fixed!