Error in JsonApiFacetsDeriver::getDerivativeDefinitions() if serverInstance is NULL

Created on 22 October 2024, 3 months ago

Problem/Motivation

Search API stores Servers and Indexes separately. It has a way to handle the (rare) case where an Index configuration becomes detached from a Server configuration (search for lone_indexes in \Drupal\search_api\IndexListBuilder).

However, \Drupal\jsonapi_search_api_facets\Plugin\facets\facet_source\JsonApiFacetsDeriver::getDerivativeDefinitions() cannot handle the "lone_index" case, and assumes that a server must always exist for an index. This results in a fatal error that looks like... Cannot call getServerInstance on NULL

Steps to reproduce

I'm having trouble reproducing this in a test environment for this issue. I encountered this on a site where were using the Configuration Split module to swap out the server backend in the CI realm; then adding content using the Default Content module.

My best guess would be something like...

  1. Install Drupal core (I used drupal-10.3.6)
  2. Install Search API (I used search_api-8.x-1.35)
  3. Install Facets (I used facets-2.0.9)
  4. Install JSON:API Search API (I used jsonapi_search_api-8.x-1.x)
  5. Install a Search API plugin that supports facets (I used Elasticsearch Connector )
  6. Install Drupal core with the standard install profile
  7. Enable a backend that supports facets
  8. Enable jsonapi_search_api_facets and all dependencies
  9. Go to /admin/config/search/search-api/add-server and create a server (I called mine test_server and used the backend that supports facets)
  10. Go to /admin/config/search/search-api/add-index and create an index for the server (I called mine test_index, indexed content, and used the test_server as the backend)
  11. Delete the server
  12. Try to add a new piece of content (i.e.: from /node/add/page

Proposed resolution

Only try deriving facet definitions when the server exists.

Remaining tasks

  1. Write a merge request
  2. Review and feedback
  3. RTBC and feedback
  4. Commit

User interface changes

None.

API changes

None.

Data model changes

None.

Feature request
Status

Active

Version

1.0

Component

Code

Created by

🇨🇦Canada mparker17 UTC-4

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024