Closed TheFox closed 2 years ago
I am getting this error after upgrading to Sonata Admin Bundle 4.11.1.
Which version did you use before ?
Do you use directly sonata.admin.request.fetcher
somewhere in your own code ?
I may be wrong but in the migration Sonata3 - Sonata4, I think we tried to reduce visibility of services and people should prefer dependency injection instead accessing them directly in the container.
Which version did you use before ?
Before 3.107.3
Do you use directly sonata.admin.request.fetcher somewhere in your own code ?
No
The problem is in \Sonata\AdminBundle\Controller\CRUDController::configureAdmin()
. You directly use sonata.admin.request.fetcher
:
$adminFetcher = $this->container->get('sonata.admin.request.fetcher');
The problem is in
\Sonata\AdminBundle\Controller\CRUDController::configureAdmin()
. You directly usesonata.admin.request.fetcher
:
$adminFetcher = $this->container->get('sonata.admin.request.fetcher');
That's different, there is https://github.com/sonata-project/SonataAdminBundle/blob/4.x/src/Controller/CRUDController.php#L92 which is working fine in my projects
How is it different?
How is it different?
There is no need for public service when using service subscribers https://symfony.com/doc/current/service_container/service_subscribers_locators.html
I have the same problem with that. Using the latest version. Any solution for that?
Any idea @jordisala1991 ?
Is it a custom controller? if so, how do you define it as a service? it could be related to not properly configured
Indeed, we need to have a small reproducer repository. Probably related to custom controllers not properly configured.
@VincentLanglet hi. Looks like issue still be there.
Got the same. No custom controller is used.
This service called here: https://github.com/sonata-project/SonataAdminBundle/blob/4.x/src/Controller/CRUDController.php#L951
Admin service definition below
sonata.admin.color:
class: SB\Admin\ColorAdmin
public: true
tags:
- { name: sonata.admin, manager_type: orm, label: "Colors" }
arguments:
- null
- SB\App\Entity\Color
- SonataAdminBundle:CRUD
calls:
- [ setTranslationDomain, [ 'SBAdmin' ] ]
you are passing a controller on third argument, pass null instead.
Same issue here, when I use Symfony\Contracts\Service\ServiceSubscriberTrait
I think that there is conflict with setContainer of ServiceSubscribeTrait and setContainer of AbstractController. Because when I reimplement ServiceSubscriberTrait without setContainer, it works.
I ran into the same issue today. I had a custom controller extending Sonata\AdminBundle\Controller\CRUDController
. In my services.yaml I defined:
App\Controller\:
resource: '../src/Controller/'
tags: ['controller.service_arguments']
calls:
- [ setContainer, [ '@service_container' ] ]
The setContainer
was providing the general container which did not contain sonata.admin.request.fetcher
. I removed the setContainer
and made sure it was tagged container.service_subscriber
(can be done through hard tagging in services.yaml or by autoconfigure). This makes it receive the service locator, containing sonata.admin.request.fetcher
among other things.
Environment
Sonata packages
show
``` $ composer show --latest 'sonata-project/*' sonata-project/admin-bundle 4.11.1 4.11.1 The missing Symfony Admin Generator sonata-project/block-bundle 4.12.0 4.12.0 Symfony SonataBlockBundle sonata-project/cache 2.2.0 2.2.0 Cache library Package sonata-project/cache is abandoned, you should avoid using it. No replacement was suggested. sonata-project/doctrine-extensions 1.16.0 1.16.0 Doctrine2 behavioral extensions sonata-project/doctrine-orm-admin-bundle 4.2.8 4.2.8 Integrate Doctrine ORM into the SonataAdminBundle sonata-project/exporter 2.11.0 2.11.0 Lightweight Exporter library sonata-project/form-extensions 1.13.1 1.14.0 Symfony form extensions sonata-project/intl-bundle 2.12.1 2.12.1 Symfony SonataIntlBundle sonata-project/translation-bundle 3.0.1 3.0.1 SonataTranslationBundle sonata-project/twig-extensions 1.5.1 1.9.1 Sonata twig extensions sonata-project/user-bundle 5.1.0 5.1.0 Symfony SonataUserBundle ```
Symfony packages
show
``` $ composer show --latest 'symfony/*' symfony/asset v4.4.40 v5.4.7 Manages URL generation and versioning of web assets such a... symfony/browser-kit v4.4.27 v5.4.3 Simulates the behavior of a web browser, allowing you to m... symfony/cache v4.4.41 v5.4.8 Provides an extended PSR-6, PSR-16 (and tags) implementation symfony/cache-contracts v2.5.1 v2.5.1 Generic abstractions related to caching symfony/config v4.4.41 v5.4.8 Helps you find, load, combine, autofill and validate confi... symfony/console v4.4.41 v5.4.8 Eases the creation of beautiful and testable command line ... symfony/css-selector v4.4.27 v5.4.3 Converts CSS selectors to XPath expressions symfony/debug v4.4.41 v4.4.41 Provides tools to ease debugging PHP code symfony/debug-bundle v4.4.27 v5.4.3 Provides a tight integration of the Symfony Debug componen... symfony/dependency-injection v4.4.41 v5.4.8 Allows you to standardize and centralize the way objects a... symfony/deprecation-contracts v2.5.1 v2.5.1 A generic function and convention to trigger deprecation n... symfony/doctrine-bridge v4.4.41 v5.4.8 Provides integration for Doctrine with various Symfony com... symfony/dom-crawler v4.4.30 v5.4.6 Eases DOM navigation for HTML and XML documents symfony/dotenv v4.4.33 v5.4.5 Registers environment variables from a .env file symfony/error-handler v4.4.41 v5.4.8 Provides tools to manage errors and ease debugging PHP code symfony/event-dispatcher v4.4.37 v5.4.3 Provides tools that allow your application components to c... symfony/event-dispatcher-contracts v1.1.12 v2.5.1 Generic abstractions related to dispatching event symfony/expression-language v4.4.41 v5.4.8 Provides an engine that can compile and evaluate expressions symfony/filesystem v4.4.39 v5.4.7 Provides basic utilities for the filesystem symfony/finder v4.4.41 v5.4.8 Finds files and directories via an intuitive fluent interface symfony/flex v1.18.6 v1.18.7 Composer plugin for Symfony symfony/form v4.4.41 v5.4.8 Allows to easily create, process and reuse HTML forms symfony/framework-bundle v4.4.41 v5.4.8 Provides a tight integration between Symfony components an... symfony/http-client-contracts v2.5.1 v2.5.1 Generic abstractions related to HTTP clients symfony/http-foundation v4.4.41 v5.4.8 Defines an object-oriented layer for the HTTP specification symfony/http-kernel v4.4.41 v5.4.8 Provides a structured process for converting a Request int... symfony/inflector v4.4.37 v5.4.3 Converts words between their singular and plural forms (En... Package symfony/inflector is abandoned, you should avoid using it. Use EnglishInflector from the String component instead. symfony/intl v4.4.41 v5.4.8 Provides a PHP replacement layer for the C intl extension ... symfony/mailer v4.4.41 v5.4.8 Helps sending emails symfony/maker-bundle v1.36.1 v1.42.0 Symfony Maker helps you create empty commands, controllers... symfony/mime v4.4.41 v5.4.8 Allows manipulating MIME messages symfony/monolog-bridge v4.4.27 v5.4.3 Provides integration for Monolog with various Symfony comp... symfony/monolog-bundle v3.7.1 v3.7.1 Symfony MonologBundle symfony/options-resolver v4.4.37 v5.4.3 Provides an improved replacement for the array_replace PHP... symfony/phpunit-bridge v5.3.10 v6.0.8 Provides utilities for PHPUnit, especially user deprecatio... symfony/polyfill-intl-grapheme v1.25.0 v1.25.0 Symfony polyfill for intl's grapheme_* functions symfony/polyfill-intl-icu v1.25.0 v1.25.0 Symfony polyfill for intl's ICU-related data and classes symfony/polyfill-intl-idn v1.25.0 v1.25.0 Symfony polyfill for intl's idn_to_ascii and idn_to_utf8 f... symfony/polyfill-intl-normalizer v1.25.0 v1.25.0 Symfony polyfill for intl's Normalizer class and related f... symfony/polyfill-mbstring v1.25.0 v1.25.0 Symfony polyfill for the Mbstring extension symfony/polyfill-php73 v1.25.0 v1.25.0 Symfony polyfill backporting some PHP 7.3+ features to low... symfony/polyfill-php80 v1.25.0 v1.25.0 Symfony polyfill backporting some PHP 8.0+ features to low... symfony/polyfill-php81 v1.25.0 v1.25.0 Symfony polyfill backporting some PHP 8.1+ features to low... symfony/property-access v4.4.41 v5.4.8 Provides functions to read and write from/to an object or ... symfony/property-info v4.4.40 v5.4.7 Extracts information about PHP class' properties using met... symfony/proxy-manager-bridge v4.4.27 v5.4.6 Provides integration for ProxyManager with various Symfony... symfony/routing v4.4.41 v5.4.8 Maps an HTTP request to a set of configuration variables symfony/security-acl v3.3.1 v3.3.1 Symfony Security Component - ACL (Access Control List) symfony/security-bundle v4.4.41 v5.4.8 Provides a tight integration of the Security component int... symfony/security-core v4.4.41 v5.4.8 Symfony Security Component - Core Library symfony/security-csrf v4.4.37 v5.4.3 Symfony Security Component - CSRF Library symfony/security-guard v4.4.37 v5.4.3 Symfony Security Component - Guard symfony/security-http v4.4.41 v5.4.8 Symfony Security Component - HTTP Integration symfony/sendgrid-mailer v4.4.30 v5.4.7 Symfony Sendgrid Mailer Bridge symfony/serializer v4.4.33 v5.4.8 Handles serializing and deserializing data structures, inc... symfony/service-contracts v2.5.1 v2.5.1 Generic abstractions related to writing services symfony/stopwatch v4.4.27 v5.4.5 Provides a way to profile code symfony/string v5.4.8 v5.4.8 Provides an object-oriented API to strings and deals with ... symfony/swiftmailer-bundle v3.5.2 v3.5.4 Symfony SwiftmailerBundle Package symfony/swiftmailer-bundle is abandoned, you should avoid using it. Use symfony/mailer instead. symfony/templating v4.4.37 v5.4.3 Provides all the tools needed to build any kind of templat... symfony/translation v4.4.41 v5.4.8 Provides tools to internationalize your application symfony/translation-contracts v2.5.1 v2.5.1 Generic abstractions related to translation symfony/twig-bridge v4.4.41 v5.4.8 Provides integration for Twig with various Symfony components symfony/twig-bundle v4.4.41 v5.4.8 Provides a tight integration of Twig into the Symfony full... symfony/validator v4.4.41 v5.4.8 Provides tools to validate values symfony/var-dumper v4.4.41 v5.4.8 Provides mechanisms for walking through any arbitrary PHP ... symfony/var-exporter v4.4.41 v5.4.8 Allows exporting any serializable PHP data structure to pl... symfony/web-profiler-bundle v4.4.31 v5.4.8 Provides a development tool that gives detailed informatio... symfony/yaml v4.4.29 v5.4.3 Loads and dumps YAML files ```
PHP version
Subject
I am getting this error after upgrading to Sonata Admin Bundle 4.11.1.
My workaround is to add the service config to my project:
Is this by design, or an error?