Problem/Motivation
Currently an exception is thrown in the SearchApiElasticsearchBackend constructor when a cluster has not yet been configured, or the cluster config can't be loaded. This causes the search API "add server" UI to hard error even if the user isn't trying to add an elastic search server.
Steps to reproduce
Enable the elasticsearch_connector module in a clean environment. Go to "add server" in the search_api admin UI.
Proposed resolution
The client instance should be created in a lazy fashion when it's actually needed. This postpones throwing the exception until search_api actually expects to see it, as well as gives code the opportunity to rely on BackendSpecificInterface::isAvailable().
Remaining tasks
Merge request- merge request !8 created by @rwohleb in #2Add tests- done by @mparker17 by #14Review and feedback- done by @sokru in #5RTBC and feedback- done by @mparker17 in #14Commit- done by @mparker17 in #15Release- released in 8.x-7.0-alpha8 by @mparker17
User interface changes
None.
API changes
Would impact anyone who is extending SearchApiElasticsearchBackend, but this is presumably rare.
Data model changes
None.
| Comment | File | Size | Author |
|---|
Issue fork elasticsearch_connector-3204443
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
rwohlebComment #4
rwohlebComment #5
sokru commentedFound few nits, otherwise looks good to me.
Comment #6
darvanenThis is also relevant to 8.x where I just encountered it.
There are a bunch of unrelated changes in the MR which make it quite difficult to review and increase the chance of a patch generated from this conflicting with other patches.
Comment #7
darvanenI tried to reroll this but I got stuck at the changes to \Drupal\elasticsearch_connector\Plugin\search_api\backend\SearchApiElasticsearchBackend::updateIndex since I'm not yet very familiar with this module and the 8.x branch has moved on since this issue was created.
I ended up here because I'm trying to evaluate this as a replacement for solr for various reasons and our environments already use PHP 8.
Happy to help however I can, just a bit stuck right now.
Comment #8
sokru commentedThis is a quick patch for 8.0.x branch. I faced the exception when none of the clusters where using "Make this cluster default connection".
Comment #9
darvanenFantastic, thanks @sokru, it does solve the WSOD at /admin/config/search/search-api/add-server but of course still throws an error that is a bit out of context. I'll come back around if this still need work once I'm more familiar with the module.
Comment #10
mparker17Going to add this to the 8.0.x review queue and note that it can be backported to 8.x-7.x.
Comment #11
mparker17Moving this to
8.x-7.x, and I've fixed the merge conflicts.Comment #12
mparker17For documentation / search-ability purposes, the error thrown at
/admin/config/search/search-api/add-serveris...Comment #13
mparker17I've fixed @sokru's review comments: thank you very much!
Comment #14
mparker17I've reviewed the code and it looks good.
I can easily reproduce the error in manual tests on the
8.x-7.xbranch (and I think it's common enough that I've bumped the Priority). I can also confirm that the code in the merge request fixes the error.There were no automated tests in the merge request, so I've added some.
I found that the
Cluster::load()call inIndexFactory::getIndexName()makes it hard to test. That code was there before, though, so I think it's out-of-scope to change that. However, I can test some of the code around it.I also wrote some tests for the
getClusterId(),getElasticClient(),getFuzziness(), andisAvailable()functions inSearchApiElasticsearchBackend. I'm assuming thatElasticsearchTest(which extends\Drupal\Tests\search_api\Kernel\BackendTestBase) tests the other functions that were modified in this merge request (i.e.:testAddFacets(),testDeleteItems(),testFieldsUpdated(),testIndexItems(),testRemoveIndex(),testSearch(),testUpdateIndex()).Given that this seems to be a common error, all of my changes (except for removing the
t()call) were to comments or tests, and I have manually tested this, I think this would be okay to merge.Comment #16
mparker17Merged! Thanks everyone! I will update this issue when the change is released.
Comment #19
a.dmitriiev commented@mparker17 this was merged 9 months ago, but unfortunately not released. Could you please create 8.x-7.0-alpha8 with the fix?
Comment #20
mparker17@a.dmitriiev, I apologize for the delay, both in releasing this fix and responding to your message! Thank you for the reminder, and thank you for your patience!
This issue has been released in 8.x-7.0-alpha8.
Comment #21
a.dmitriiev commentedThank you! And no problem :)