After updating to Drupal 10.3, facets stop working, at least with ajax views.

The reason is the calls to Request::create(), without setting a session on the created requests, in combination with core issue #3413153: Remove calls to Request::hasSession() removing all calls to $request->hasSession() and assuming session exists.

Proposed resolution copy the logic of DrupalKernel::initializeEphemeralSession() to add a mock session on the created requests

Comments

s.messaris created an issue. See original summary.

s.messaris’s picture

StatusFileSize
new2.47 KB
new2.5 KB

Here are 2 patches, one for 2.0.x, and one for 2.0.7.

pbabin’s picture

StatusFileSize
new2.36 KB

All credit goes to @s.messaris . . . . 2.0.8 came out today and the patch for 2.0.7 doesn't work anymore. Copied and pasted the proposed changes and created a 2.0.8 patch.

Thank you @s.messaris for getting a handle on the "session has not been set" issue.

elc’s picture

Please note that MockArraySessionStorage is only added to TESTS for KernelTestBase, and BrowserTestBase (and drush but that doesn't seem relevant here).

It should not be added to normal operation code.

I would suspect this issue is more to do with session not being specifically saved and added to the response.

pbabin’s picture

@ELC - I greatly appreciate you chiming in on this. I'm still "relatively" new to Drupal so getting feedback like this is extremely helpful.

I'm curious as to why an earlier approach for pre 2.0.8 isn't also under your rubric as the patch I submitted was just a copy of previous work. Is it safe to assume that this entire approach isn't recommended?

I came this way from Facets with AJAX not working in most of situations where Patch 237 addressed our issue with the session not being set and this comment directs individuals over to this issue as a proposed solution for the exact issue.

Since 2.0.8 came out, the patch 237 no longer works and the patch I proposed is not recommended so we are still stuck with facets that are completely broken because we are getting the "session has not been set" error coming up.

Any recommendations on how to address this issue in a more Drupal appropriate way is greatly appreciated.

elc’s picture

Status: Active » Closed (duplicate)

My apologies, I missed that the previous patches were also adding test classes into running code.

The issue for me is actually a combination of these:

Unfortunately, they do not apply cleanly because they are all changing the same code. I added a custom patch to 3466566 to apply after 3052574.

I've had to patch all of them in to get my situation working. It would be ideal if all of this was fixed as one. There is a META issue #3075378: [META] Overview of Facets + Ajax issues for the known issues of Facets + Ajax, of which there are a few. Doesn't look like 3466566 has been made part of that yet. This Ajax issue has been hanging around for a very long time.

The session issue is addressed in #3052574-254: Facets with AJAX not working in most of situations, so closing this as duplicate.

cb_govcms’s picture

Status: Closed (duplicate) » Needs review
StatusFileSize
new716 bytes

#3052574: Facets with AJAX not working in most of situations has an elaborate fix for a different issue that happens to also resolve this - but that issue has been open for 5 years and may not land any time soon. I'm attaching a patch for this issue that just resolves the Session error introduced in Core 10.3

tfranz’s picture

I tested the patch #7 with 2.0.9 and it solves the Session error.

drupix’s picture

Same for me, the patch #7 with 2.0.9 solves the Session error.

treckstar’s picture

Can confirm that the patch in #3 for 2.0.8 worked for me in 2.0.9.
Thank you!

prudloff’s picture

Status: Needs review » Reviewed & tested by the community

Several people confirmed the patch fixes their problem.
(It also fixed it for us.)

w01f’s picture

Also confirming patch #3 appears to solve issue on 10.4.2.

ludo.r’s picture

Patch #3 solves the issue (however patch #7 seems a lot simpler/cleaner but I didn't test it).

trebormc’s picture

Patch #7 solves the issue