Core: 2.4.0 beta is not compatible with symfony 4.2

Created on 18 Jan 2019  路  17Comments  路  Source: api-platform/core

I was too excited to test 2.4.0 so I updated it, but it failed:

In CheckExceptionOnInvalidReferenceBehaviorPass.php line 86:

  The service "api_platform.messenger.data_persister" has a dependency on a non-existent service "message_bus".           

We are using

symfony/symfony                      v4.2.1           The Symfony PHP framework

(yes, no flex, because it's an "old" application, but we get new releases anyway)

bug

Most helpful comment

For anyone getting error The service "api_platform.messenger.data_persister" has a dependency on a non-existent service "message_bus". like I did, just add

api_platform:
    mapping:
        paths: ['%kernel.project_dir%/src/Entity']
    messenger:
        enabled: false

To config/packages/api_platform.yaml, to tell API Platform not to use messenger.

All 17 comments

I fixed this in an upgraded Symfony 3 application by composer require symfony/messenger and adding the following under framework to config.yml:

messenger:
  default_bus: ~

This may need a fix on symfony's side no?

IMHO, no. either you make the messenger component mandatory, or you use it only if the service is here.

I'll fix this asap

Thanks

Mhh it's weird, we do have a check and load the messenger.xml only when the interface exists:

https://github.com/api-platform/core/blob/2.4/src/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php#L154-L156

Class exisit is different from service exisit

@soyuka @lyrixx messenger_bus is a private service. When running off of the latest api-platform 2.4, this fails to load the messenger component, since $container->has('message_bus') is always false.

Checking how symfony's FrameworkBundle works, they don't ever check if a service exists, instead they do an interface exists check (like what we currently have and what was there previously), and in some cases, they check a config value to see if the module should be enabled or not.

@lyrixx correct me if i'm wrong, but if if you were getting that error, that means that you had symfony/messenger component installed but due to some configuration, the message bus service didn't exist.

I think we should revert the $container->has('messenger.message_bus') since it doesn't work, and possibly see about adding a config option to enable/disable messenger integration entirely since messenger isn't a stable component.

Y, re-reading @lyrixx's original post, it makes sense what's going on. You have the entire SF framework loaded which would cause the messenger class to exist, but you did NOT have messenger services loaded.

@soyuka @dunglas I think the only way to get around this is to allow a feature flag for messenger to allow people who load the entire sf framework to disable certain parts.

Thanks @ragboyjr !

For anyone getting error The service "api_platform.messenger.data_persister" has a dependency on a non-existent service "message_bus". like I did, just add

api_platform:
    mapping:
        paths: ['%kernel.project_dir%/src/Entity']
    messenger:
        enabled: false

To config/packages/api_platform.yaml, to tell API Platform not to use messenger.

I'm reproducing the issue with symfony/symfony 4.2.4, api-platform/core 2.4.2, and messenger not enabled (no symfony flex).

Oh, I've just seen that the issue has been solved in #2489 by adding the boolean configuration

I don't think that fix is enough. It still requires the user to manually disable Messenger integration. Things should not be broken out of the box.

My comments

Class exist is different from service exist

Is still relevant :)

@lyrixx It should be fixed in https://github.com/api-platform/core/pull/2721

Was this page helpful?
0 / 5 - 0 ratings