Problem/Motivation

After upgrading to Drupal 10.3.0 I'm getting 404 when search via autocomplete widget from select2_facets.

Debug shown that $this->facetManager->build($facet); fails with watchdog message Session has not been set. Because we executing facets in a new request context I assume that there was something wrong with instantinating it.
Checking drupal core codebase for similar case I found core comment module has such example:

$redirect_request = Request::create(...);
// Carry over the session to the subrequest.
$redirect_request->setSession($request->getSession());

Git blame on https://git.drupalcode.org/project/drupal/-/blame/10.3.0/core/modules/co... shown the #3413153: Remove calls to Request::hasSession() issue cased changes went into the core.

Note: I assume that this error also will be observable in facets module too because there are Request::create entries in facets/src/Controller/FacetBlockAjaxController.php, there is even an issue #3052574-239: Facets with AJAX not working in most of situations

Steps to reproduce

Use drupal core 10.3.0, and select2 1.15.0, configure search api, views, facets and widget.

Proposed resolution

Set excplicitly session for sub request:

      $new_request = $this->createRequestFromPath($selection_settings['path']);
      $new_request->setSession($request->getSession());

Issue fork select2-3464151

Command icon 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

vlad.dancer created an issue. See original summary.

vlad.dancer’s picture

Assigned: vlad.dancer » Unassigned
Status: Active » Needs review
elusivemind’s picture

Be sure you have patched Facets 2.x for Drupal 10.3 until it is rolled into their release

https://www.drupal.org/project/facets/issues/3052574

lakdev’s picture

Looks good to me. We had the same issue and the proposed changes fixed the bug for us.

bobi-mel’s picture

Status: Needs review » Reviewed & tested by the community

Works well for Drupal 10.3.6

very_random_man’s picture

+1 for testing

This fixed a 'session has not been set' error for me with select2 facets I experienced after upgrading to D10.3, in conjunction with the Facets patch in the issue linked above.