Search API Solr 8.x depends on the solarium library to communicate to Solr servers.

It was a great move for 8.x since other projects like Typo3 or Wordpress and other PHP frameworks joined forces to collaborate on one library for Solr.

Internally solarium leverages the symfony/event-dispatcher for event handling. Unfortunately with the release of Symfony 4.3 the event dispatching changed: https://symfony.com/blog/new-in-symfony-4-3-simpler-event-dispatching

Since solarium has more symfony or pure PHP users than Drupal users we couldn't block the changes in solarium 5.1.x to be compatible to the new event dispatching for symfony >= 4.3.

With the release of the new event-dispatcher, the symfony project released a backward compatibility layer for symfony 3.4 to 4.2 which allows to only update the event-dispatcher in your symfony 3.4 based project without upgrading symfony entirely in order to use libraries that already switched to the new event handling. Drupal 8.x is such a project. And solarium 5.1 is such a library.
But drupal needs to actively allow the installation of the compatibility layer. There's an open core issue with a patch that addresses this problem:
#2876675: Allow symfony/event-dispatcher 4+ to be installed in Drupal 8.

So unless this patch gets committed to drupal 8 core, the installation of solarium 5.1.x via composer gets blocked. drupal 9 core is not affected.

On the other hand we got bug reports in the Search API Solr issue queue that could be solved by simply upgrading from solarium 5.0.x to 5.1.x because the cause for such issues have been solved in the library already. Examples are boost queries and rerank queries that contain apostrophes which happen in languages like French. These might lead to fatal errors caused by unhandled Solr Exceptions or - in the best case - just no results. Therefore we decided to recommend updating to solarium 5.1 and to raise an error in the drupal status report of your installation.

So how can you update to solarium 5.1.x or newer if I still use Drupal 8?

If you didn't install drupal itself via composer and you just manage contrib via composer you could apply https://www.drupal.org/files/issues/2019-09-17/2876675-48.Fix-symfony-ve... to drupal core.

If you manage your entire project via composer, the patch needs to be applied before composer runs. That could be done by cloning drupal core and by setting your repository with the patch applied as repository in the composer.json. But I don't recommend that!

The "easiest" way is to bypass the drupal core restriction by faking the event-dispatcher version number to satisfy drupal core's restriction:

composer require symfony/event-dispatcher:"4.3.11 as 3.4.35"

The downside of this approach is that other third party libraries or frameworks that leverage the symfony event dispatcher directly instead of drupal's own event dispatcher run into errors. The civicrm integration is such a third party tool.

If the core patch gets committed, composer would be able to handle all these dependencies and to provide your individual set of compatible versions.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mkalkbrenner created an issue. See original summary.

mkalkbrenner’s picture

Search API Solr 8.x depends on the solarium library to communicate to Solr servers.

It was a great move for 8.x since other projects like Typo3 or Wordpress and other PHP frameworks joined forces to collaborate on one library for Solr.

Internally solarium leverages the symfony/event-dispatcher for event handling. Unfortunately with the release of Symfony 4.3 the event dispatching changed: https://symfony.com/blog/new-in-symfony-4-3-simpler-event-dispatching

Since solarium has more symfony or pure PHP users than Drupal users we couldn't block the changes in solarium 5.1.x to be compatible to the new event dispatching for symfony >= 4.3.

With the release of the new event-dispatcher, the symfony project released a backward compatibility layer for symfony 3.4 to 4.2 which allows to only update the event-dispatcher in your symfony 3.4 based project without upgrading symfony entirely in order to use libraries that already switched to the new event handling. Drupal 8.x is such a project. And solarium 5.1 is such a library.
But drupal needs to actively allow the installation of the compatibility layer. There's an open core issue with a patch that addresses this problem:
#2876675: Allow symfony/event-dispatcher 4+ to be installed in Drupal 8.

So unless this patch gets committed to drupal core, the installation of solarium 5.1.x via composer gets blocked.

On the other hand we got bug reports in the Search API Solr issue queue that could be solved by simply upgrading from solarium 5.0.x to 5.1.x because the cause for such issues have been solved in the library already. Examples are boost queries and rerank queries that contain apostrophes which happen in languages like French. These might lead to fatal errors caused by unhandled Solr Exceptions or - in the best case - just no results. Therefore we decided to recommend updating to solarium 5.1 and to raise an error in the drupal status report of your installation.

So how can you update to solarium 5.1.x?

If you didn't install drupal itself via composer and you just manage contrib via composer you could apply https://www.drupal.org/files/issues/2019-09-17/2876675-48.Fix-symfony-ve... to drupal core.

If you manage your entire project via composer, the patch needs to be applied before composer runs. That could be done by cloning drupal core and by setting your repository with the patch applied as repository in the composer.json. But I don't recommend that!

The "easiest" way is to bypass the drupal core restriction by faking the event-dispatcher version number to satisfy drupal core's restriction:
composer require symfony/event-dispatcher:"4.3.4 as 3.4.99"
The downside of this approach is that other third party libraries or frameworks that leverage the symfony event dispatcher directly instead of drupal's own event dispatcher run into errors. The civicrm integration is such a third party tool.

If the core patch gets committed, composer would be able to handle all these dependencies and to provide your individual set of compatible versions.

mkalkbrenner’s picture

PatrickMichael’s picture

Thank you #2 helped me update

mkalkbrenner’s picture

.

mkalkbrenner’s picture

Issue summary: View changes
rodtatham’s picture

I was having an issue where my Solr search only returned one or two results rather than the 21 results I expected. I had an error on the SEARCH API page of my drupal site, reading:

Solarium 5.0.2 is too old and has known issues. In order to get composer to upgrade solarium to a recent version a core patch or a workaround is required. Have a look at this Core issue and this Search API Solr issue.

Thanks to this page, I ran the following which fixed my search issue:-

#> composer require symfony/event-dispatcher:"4.3.4 as 3.4.99"
#> composer update

- note that I was happy to update the whole Drupal instance. Site wasn't yet live.

Cheers

TrevorBradley’s picture

Thank you @mkalkbrenner for taking the time to document this!

SivaprasadC’s picture

Thank you @mkalkbrenner and @rodtatham, it helped me to resolve the error

mkalkbrenner’s picture

Issue summary: View changes
ressa’s picture

Thanks @mkalkbrenner. Should all installations tweak the version constraints, or is it mostly relevant for fresh installations?

mkalkbrenner’s picture

It's recommended to update existing installations to the latest version:
composer require symfony/event-dispatcher:"4.3.4 as 3.4.99"

ressa’s picture

I am sorry, I wasn't precise enough. I meant to ask if installations, which have already run the command, need to run the updated command again?

mstrelan’s picture

FWIW if you're using the new drupal/core-recommended package it explictly requires symfony/event-dispatcher:v3.4.35 for Drupal 8.8.1. So for now you can use this code:

composer require symfony/event-dispatcher:"4.3.4 as 3.4.35"

You'll likely have to bump this for future updates which is a real pain. It's probably easier to apply the patch.

ressa’s picture

Thanks for the comment @mstrelan. I hope the issue gets settled soon in #2876675: Allow symfony/event-dispatcher 4+ to be installed in Drupal 8, which has been RTBC since 16. October 2019 ...

RealityBitesYou’s picture

Theoretically you could also override the composer managed solarium library (and dependencies) by putting them in the vendor tree of the module, the adjust the module to use it from the module's vendor tree.

This would remove the dependency issues for that module, until the drupal/civicrm/symfony stuff gets sorted.

I've done this to handle similar issues where some module requires an older version of a library that would break everything if it were in the master vendor tree.

There's a reason you can define and run your own autoloaders ;)

kebne’s picture

I have tried both the patch in #15 https://www.drupal.org/project/search_api_solr/issues/3083601 and this:

composer require symfony/event-dispatcher:"4.3.4 as 3.4.99" drupal/search_api_solr

Problem 1
- drupal/core-recommended 8.8.2 requires symfony/event-dispatcher v3.4.35 -> satisfiable by symfony/event-dispatcher[v3.4.35] but these conflict with your requirements or minimum-stability.
- drupal/core-recommended 8.8.2 requires symfony/event-dispatcher v3.4.35 -> satisfiable by symfony/event-dispatcher[v3.4.35] but these conflict with your requirements or minimum-stability.
- drupal/core-recommended 8.8.2 requires symfony/event-dispatcher v3.4.35 -> satisfiable by symfony/event-dispatcher[v3.4.35] but these conflict with your requirements or minimum-stability.
- Installation request for drupal/core-recommended (locked at 8.8.2, required as ^8.8) -> satisfiable by drupal/core-recommended[8.8.2].

What next??

mstrelan’s picture

@kebne read #15

kebne’s picture

@mstrelan

thx that worked! do you know why the patch #15 https://www.drupal.org/project/search_api_solr/issues/3083601 doesn't work?

mstrelan’s picture

All that patch does is allow the older version of solarium to be installed and display warnings that it needs updating.

mkalkbrenner’s picture

- drupal/core-recommended 8.8.2 requires symfony/event-dispatcher v3.4.35 -> satisfiable by symfony/event-dispatcher[v3.4.35] but these conflict with your requirements or minimum-stability.
- drupal/core-recommended 8.8.2 requires symfony/event-dispatcher v3.4.35 -> satisfiable by symfony/event-dispatcher[v3.4.35] but these conflict with your requirements or minimum-stability.
- drupal/core-recommended 8.8.2 requires symfony/event-dispatcher v3.4.35 -> satisfiable by symfony/event-dispatcher[v3.4.35] but these conflict with your requirements or minimum-stability.
- Installation request for drupal/core-recommended (locked at 8.8.2, required as ^8.8) -> satisfiable by drupal/core-recommended[8.8.2].

composer.json in core states:
"symfony/event-dispatcher": "~3.4.0"
That allows to install any 3.4.x version.

But by leveraging drupal/core-recommended you explicitly decided to use exactly pinned versions as listed at https://packagist.org/packages/drupal/core-recommended#8.8.2

From my point of view drupal/core-recommended is against the composer principle. But anyway, this should fix the issue (temporaryly):
composer require symfony/event-dispatcher:"4.3.11 as 3.4.35"

j.b’s picture

comment #15 should be added in the INSTALL.md.

mkalkbrenner’s picture

Title: How to upgrade to solarium 5.1.x » How to upgrade to solarium 5.1.x, 5.2.x or 6.0.x
Issue summary: View changes
d_f’s picture

It's in particular the symfony/dependency-injection and symfony/event-dispatcher packages that are frozen in time. Both of these are two full versions ahead from what drupal core mandates, and these are drop in compatible with the v:~3.4.x that drupal ships with. I'm trying to install a few packages from packagist that need both of them to be >4.4, and it turns out to be nigh impossible. Installing older versions of the packages is definitely not optimal.

I assume the symfony/console and the symfony/class-loader packages are also suffering the same fate.

Can we like petition the powers that be to up the version of these in core or something?

Edit: I'm an idiot. I just checked and the actual list of packages in dire need of updating is embarrassing. Are we waiting for Drupal 9 to update these?

mkalkbrenner’s picture

@d_f check #2876675: Allow symfony/event-dispatcher 4+ to be installed in Drupal 8

i decided to note waste time anymore with arguing and delivering all sub-tasks the core maintainers requested. At the end nobody cared about it and the community of Solr users wasn't able to create enough awareness or to point out it needs.
I could have spent that time in more productive work for the community.

mkalkbrenner’s picture

Issue summary: View changes
mkalkbrenner’s picture

Version: 8.x-3.x-dev » 4.x-dev
mkalkbrenner’s picture

Version: 4.x-dev » 8.x-3.x-dev
mkalkbrenner’s picture

Version: 8.x-3.x-dev » 4.x-dev
hanoii’s picture

Does what it now says on #2876675-78: Allow symfony/event-dispatcher 4+ to be installed in Drupal 8 means this won't be an issue on D9?

Nevemind, just saw it on the issue summary, sorry.

geerlingguy’s picture

mkalkbrenner’s picture

Status: Active » Fixed

Great news!

With the the new 4.1.0 release the pain should be over. Search API Solr 4.1.0 requires solarium 6.
In solarium 6 we just replaced the hard dependency to symfony's event dispatcher by a pure PSR-14 compliant event dispatching.

Search API Solr 4.1.0 contains a bridge between Drupal's non-standard-compliant event dispatching and solarium's PSR-14-compliant event dispatching. See my recent comment on #2833771: PSR-14 (Events) development and support for details.

If you upgrade to 4.1.0 don't forget to revert to the symfony/event-dispatcher version that corresponds with your Drupal Core's requirement.

KlemenDEV’s picture

Thank you for fixing this, this was quite an annoyance ;)

mkalkbrenner’s picture

"Fixing" is the wrong term. It is just a better workaround as it requires no action on your side.

Unfortunately drupal becomes more and more a legacy software that requires such hacks ;-)

carstenG’s picture

Hmm updated to 4.1.0 and removed the
composer require symfony/event-dispatcher:"4.3.11 as 3.4.35"

But now I get the following error when browsing the site.

Fatal error: Declaration of Drupal\search_api_solr\Solarium\EventDispatcher\Psr14Bridge::dispatch($event, ?Symfony\Component\EventDispatcher\Event $null = NULL) must be compatible with Psr\EventDispatcher\EventDispatcherInterface::dispatch(Psr\EventDispatcher\object $event)

Any hints?

mkalkbrenner’s picture

Did you run composer update?

Please open a new issue.

mkalkbrenner’s picture

BTW the tests run against Drupal 8.8 with symfony 3.4 and Drupal 9 using symfony 4.

carstenG’s picture

Well I did an update --with-dependencies on drupal/core drupal /search_api and drupal/search_api_solr
Therefore I am on Drupal 8.9

OK I'll raise a new issue

solideogloria’s picture

I was able to update and browse a site fine on Drupal 8.9 with PHP 7.3. No errors. However, I haven't tested the Search API yet.

carstenG’s picture

My problem from #36 was because of PHP7.1

KlemenDEV’s picture

Update worked fine on Drupal 8.9, PHP 7.4

ecvandenberg’s picture

In #38 it says

If you upgrade to 4.1.0 don't forget to revert to the symfony/event-dispatcher version that corresponds with your Drupal Core's requirement.

I know it's a composer question, but how do you do that?
The work around was composer require symfony/event-dispatcher:"4.3.11 as 3.4.35". So how to revert that?

solideogloria’s picture

Simply delete that line from your composer.json file and composer update, or if you must use CLI, I think you can run composer remove symfony/event-dispatcher.

dmlb2000’s picture

I'm not able to run the following to create a new project going directly to Drupal 8.9.1.

I'm following the instructions from here to create the project.

composer create-project 'drupal/recommended-project:^8' drupal-site
pushd drupal-site
composer require drupal/search_api_solr
composer require symfony/event-dispatcher:"4.3.11 as 3.4.41"
popd

I'm using php 7.4 and composer 1.10.1 the output of this is the following... stipped straight to the error...

+ composer require 'symfony/event-dispatcher:4.3.11 as 3.4.41'
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - drupal/core-recommended 8.9.1 requires symfony/event-dispatcher v3.4.41 -> satisfiable by symfony/event-dispatcher[v3.4.41] but these conflict with your requirements or minimum-stability.
    - drupal/core-recommended 8.9.1 requires symfony/event-dispatcher v3.4.41 -> satisfiable by symfony/event-dispatcher[v3.4.41] but these conflict with your requirements or minimum-stability.
    - drupal/core-recommended 8.9.1 requires symfony/event-dispatcher v3.4.41 -> satisfiable by symfony/event-dispatcher[v3.4.41] but these conflict with your requirements or minimum-stability.
    - Installation request for drupal/core-recommended (locked at 8.9.1, required as ^8.8) -> satisfiable by drupal/core-recommended[8.9.1].


Installation failed, reverting ./composer.json to its original content.

If search_api_solr is installed after the symfony/event-dispatcher it seems to work. This is different from before...

composer create-project 'drupal/recommended-project:^8' drupal-site
pushd drupal-site
composer require symfony/event-dispatcher:"4.3.11 as 3.4.41"
composer require drupal/search_api_solr
popd
ecvandenberg’s picture

When you install Drupal 8.9.1 you do not need composer require symfony/event-dispatcher:"4.3.11 as 3.4.41" anymore.

mstrelan’s picture

When you install Drupal 8.9.1 you do not need composer require symfony/event-dispatcher:"4.3.11 as 3.4.41" anymore.

Wait, what? I think you mean when you install Search API Solr 4.1.x. Drupal 8.9.1 still uses symfony/event-dispatcher 3.4.41.

ecvandenberg’s picture

What I mean is that the work around suggested in in this issue is not required anymore. When you install Drupal 8.9.1 and Search API Solr 4.1.x you should be fine. Also check the release notes of Search API Solr. It's explained there.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

jcandan’s picture

I have Drupal 8.9.1 and search_api_solr:4.1.4. According to #48, this issue is resolved. However, I still see the status report error at /admin/reports/status:

A screenshot of the status report error.

Should a new ticket be created to address removing this error, or is this current ticket appropriate?

jcandan’s picture

Disregard #50.