SonataAdminBundle: Conflict with DI extra bundle

Hi !

I have an issue with the last release of SonataAdminBundle (3.11.*).

Environment

  • Environment dev
  • Debug enabled
  • PHP version 5.6.29-0+deb8u1

Sonata packages

$ composer show sonata-project/*
sonata-project/admin-bundle              3.10.3             The missing Symfony Admin Generator
sonata-project/block-bundle              3.3.0              Symfony SonataBlockBundle
sonata-project/cache                     1.0.7              Cache library
sonata-project/core-bundle               3.2.0              Symfony SonataCoreBundle
sonata-project/datagrid-bundle           dev-master 9c6f293 Symfony SonataDatagridBundle
sonata-project/doctrine-extensions       1.0.2              Doctrine2 behavioral extensions
sonata-project/doctrine-orm-admin-bundle 3.0.0              Symfony Sonata / Integrate Doctrine...
sonata-project/easy-extends-bundle       2.1.10             Symfony SonataEasyExtendsBundle
sonata-project/exporter                  1.7.0              Lightweight Exporter library
sonata-project/intl-bundle               dev-master d2eab1c Symfony SonataIntlBundle
sonata-project/media-bundle              dev-master master  

Symfony packages

$ composer show symfony/*
symfony/assetic-bundle     v2.8.1  Integrates Assetic into Symfony2
symfony/monolog-bundle     v2.12.1 Symfony MonologBundle
symfony/polyfill-apcu      v1.3.0  Symfony polyfill backporting apcu_* functions to lower PHP v...
symfony/polyfill-intl-icu  v1.3.0  Symfony polyfill for intl's ICU-related data and classes
symfony/polyfill-mbstring  v1.3.0  Symfony polyfill for the Mbstring extension
symfony/polyfill-php54     v1.3.0  Symfony polyfill backporting some PHP 5.4+ features to lower...
symfony/polyfill-php55     v1.3.0  Symfony polyfill backporting some PHP 5.5+ features to lower...
symfony/polyfill-php56     v1.3.0  Symfony polyfill backporting some PHP 5.6+ features to lower...
symfony/polyfill-php70     v1.3.0  Symfony polyfill backporting some PHP 7.0+ features to lower...
symfony/polyfill-util      v1.3.0  Symfony utilities for portability of PHP codes
symfony/security-acl       v3.0.0  Symfony Security Component - ACL (Access Control List)
symfony/swiftmailer-bundle v2.4.2  Symfony SwiftmailerBundle
symfony/symfony            v2.8.16 The Symfony PHP framework

PHP version

PHP version 5.6.29-0+deb8u1

Subject

With the last release of SonataAdmin, I have some issues with DI Extra Bundle see this issue https://github.com/schmittjoh/JMSDiExtraBundle/issues/266

All services are not found with basic service annotation:

/**
 * @DI\Service("app.indexer.category")
 */
class CategoryIndexer

Also, it could be a conflict with my JMS configuration:

jms_di_extra:
    locations:
        all_bundles: false
        bundles: [AppBundle, ApiBundle]
        directories: ["%kernel.root_dir%/../src"]

I tried to use "jms/di-extra-bundle": "^1.7" but the problem still persists…

My workaround so far: rollback to SonataAdminBundle 3.10.* 😕

Steps to reproduce

  1. Update to SonataAdminBundle 3.11.*
  2. Declare services with JMSDiExtraBundle @DI\service()
  3. Try to get the service (dep injection or get from container)

Expected results

All services in AppBundle which uses DI annotation must be found as service.

Actual results

Services declared with DI annotation are not found.

[Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException]                                           
  The service "fos_elastica.listener.app.category" has a dependency on a non-existent service "app.indexer.category". 

Any idea ?

Thanks for your amazing work and your help !

If you need anything ask for it ! 😉

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 60 (37 by maintainers)

Commits related to this issue

Most upvoted comments

I had the same issue, and I fixed it with this lines in config.yml

jms_di_extra:
   annotation_patterns:
      - "JMS\\DiExtraBundle\\Annotation"

This is causing other issues as well:

[Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException]                       
The service "security.firewall" has a dependency on a non-existent service "security.request_ma  
tcher.5314eeb91110adf24b9b678372bb11bbe00e8858c519c088bfb65f525181ad3bf573fd1d".                 

I don’t know exactly what is happening there, however I git bisected it down to commit 216933fa18e8beb3d1dfe7f4a1aaed78da652a3c as well.

Please don’t unconditionally and unoverridably mess with the configuration of another completely unrelated bundle. The configuration prepend in symfony isn’t meant for that, it’s there so that closely related bundles can share a common configuration. The way you are adding the pattern, there is no way a user can remove it from annotation_patterns if she doesn’t want it (frankly, I don’t see the point of the Admin annotation anyway, AFAICT there’s nothing you can do with it that you can’t do with DiExtraBundle’s Tag annotation). You aren’t changing a default value, you are in essence editing the users config.yml without asking (or even telling) him.

The way this should be done properly is by not adding something magically and documenting that in order to use the Admin annotation you have to configure DiExtraBundle appropriately.

https://github.com/schmittjoh/JMSDiExtraBundle/blob/master/Config/ServiceFilesResource.php#L40

This seems to be the problem. Always looks for JMS\DiExtraBundle\Annotation, therefore it is never fresh.

Providing the pattern as a constructor argument solves the problem… I will submit a PR soon

It’s definitely a BC break for users using 3.10 or earlier and updating to 3.11 while using DiExtraBundle or later right now…

What you guys don’t understand is that the BC-break from 3.10 to 3.11 is done. Now it’s the new behavior, and it might work for some people. You’re trying to fix your use case, but what about people using the other use case, which, by the way, is the documented one? What about people that did not do the upgrade from 3.10 to 3.11 , but will update from 3.10 or lower to 3.12? They will feel just like you two. Don’t do unto others what you don’t want others to do unto you.

I can confirm the issue, it is blocking to update SonataAdmin to the current version when using JMSDiExtraBundle. I’ve noticed similar slowness on my project.

Even when using the PR from @Padam87 which corrects most of the performance issues, I still have my project ~ 30% slower than before this update in SonataAdmin.

Yep. I’ve reverted to 3.10, all good. Tried adding the annotation manually, took pics 😃 before after

Happy holiday then!

@greg0ire hey, I will make the PR sonata-side next week, I’m on holidays right now too.

Ok then, lets see what @Nightbr says. I could be wrong but checking for keys (just the presence/absence) should be enought to guess if values come from the developer. Unfortunatly (or not) I’m on holidays until next week and I can’t check 😃

The change to the Configuration class would have to be done in the JMSDiExtraBundle where it is defined. However, I am not sure that is intended.