Skip to content

The service "serializer.normalizer.translatable" has a dependency on a non-existent service "translator" #52847

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
greg0ire opened this issue Dec 1, 2023 · 1 comment

Comments

@greg0ire
Copy link
Contributor

greg0ire commented Dec 1, 2023

Symfony version(s) affected

6.4.0

Description

After upgrading an application that has the translator disabled from 6.3 to 6.4, I'm getting the following error when running any command:


In CheckExceptionOnInvalidReferenceBehaviorPass.php line 88:

  [Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException]
  The service "serializer.normalizer.translatable" has a dependency on a non-existent service "translator".


Exception trace:
  at /app/vendor/symfony/dependency-injection/Compiler/CheckExceptionOnInvalidReferenceBehaviorPass.php:88
 Symfony\Component\DependencyInjection\Compiler\CheckExceptionOnInvalidReferenceBehaviorPass->processValue() at /app/vendor/symfony/dependency-injection/Compiler/AbstractRecursivePass.php:90
 Symfony\Component\DependencyInjection\Compiler\AbstractRecursivePass->processValue() at /app/vendor/symfony/dependency-injection/Compiler/CheckExceptionOnInvalidReferenceBehaviorPass.php:51
 Symfony\Component\DependencyInjection\Compiler\CheckExceptionOnInvalidReferenceBehaviorPass->processValue() at /app/vendor/symfony/dependency-injection/Compiler/AbstractRecursivePass.php:99
 Symfony\Component\DependencyInjection\Compiler\AbstractRecursivePass->processValue() at /app/vendor/symfony/dependency-injection/Compiler/CheckExceptionOnInvalidReferenceBehaviorPass.php:51
 Symfony\Component\DependencyInjection\Compiler\CheckExceptionOnInvalidReferenceBehaviorPass->processValue() at /app/vendor/symfony/dependency-injection/Compiler/AbstractRecursivePass.php:90
 Symfony\Component\DependencyInjection\Compiler\AbstractRecursivePass->processValue() at /app/vendor/symfony/dependency-injection/Compiler/CheckExceptionOnInvalidReferenceBehaviorPass.php:51
 Symfony\Component\DependencyInjection\Compiler\CheckExceptionOnInvalidReferenceBehaviorPass->processValue() at /app/vendor/symfony/dependency-injection/Compiler/AbstractRecursivePass.php:48
 Symfony\Component\DependencyInjection\Compiler\AbstractRecursivePass->process() at /app/vendor/symfony/dependency-injection/Compiler/CheckExceptionOnInvalidReferenceBehaviorPass.php:42
 Symfony\Component\DependencyInjection\Compiler\CheckExceptionOnInvalidReferenceBehaviorPass->process() at /app/vendor/symfony/dependency-injection/Compiler/Compiler.php:80
 Symfony\Component\DependencyInjection\Compiler\Compiler->compile() at /app/vendor/symfony/dependency-injection/ContainerBuilder.php:767
 Symfony\Component\DependencyInjection\ContainerBuilder->compile() at /app/vendor/symfony/http-kernel/Kernel.php:506
 Symfony\Component\HttpKernel\Kernel->initializeContainer() at /app/vendor/symfony/http-kernel/Kernel.php:763
 Symfony\Component\HttpKernel\Kernel->preBoot() at /app/vendor/symfony/http-kernel/Kernel.php:126
 Symfony\Component\HttpKernel\Kernel->boot() at /app/vendor/symfony/framework-bundle/Console/Application.php:190
 Symfony\Bundle\FrameworkBundle\Console\Application->registerCommands() at /app/vendor/symfony/framework-bundle/Console/Application.php:72
 Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /app/vendor/symfony/console/Application.php:175
 Symfony\Component\Console\Application->run() at /app/bin/console:49

How to reproduce

# config/packages/framework.yaml

framework:
    translator:
        enabled: false

Possible Solution

Add a check here:

if (!class_exists(Translator::class)) {
$container->removeDefinition('serializer.normalizer.translatable');
}
? This will probably require passing the translator configuration to the method where that check resides.

Additional Context

Switching enabled to true fixes the issue.

@greg0ire
Copy link
Contributor Author

greg0ire commented Dec 1, 2023

Caused by #50212 I think, Cc @Jean-Beru

nicolas-grekas added a commit that referenced this issue Dec 1, 2023
…r is disabled (Jean-Beru)

This PR was merged into the 6.4 branch.

Discussion
----------

[Serializer] Fix TranslatableNormalizer when the Translator is disabled

| Q             | A
| ------------- | ---
| Branch?       | 6.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        | Fix #52847
| License       | MIT

Fix #52847 by removing the `serializer.normalizer.translatable` when the Translator is disabled. FYI, if the Translator is enabled but the class does not exist, an error is already raised before `Translation support cannot be enabled as the Translation component is not installed. Try running "composer require symfony/translation". `

Commits
-------

319a0fe [Serializer] Remove TranslatableNormalizer service when the Translator is disabled
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants