lexik / LexikTranslationBundle

This Symfony bundle allow to import translation files content into the database and provide a GUI to edit translations.
MIT License
427 stars 262 forks source link

Problem only in production environment with _service_doctrine.orm.default_listeners.attach_entity_listeners #464

Closed Pesulap closed 1 week ago

Pesulap commented 1 week ago

Hi, I have updated my project to Symfony 7.1.4 and everything works as it should on dev environment, but if I switch to production environment, it throws this error when I clear the cache:

obrazek

Anyone know what to do?

Thank you

bartmcleod commented 1 week ago

@Pesulap When asking this type of question please also post the text of the error. This will help indexing your issue in search engines so that others will see this and eventual answer might help them. Also, for people that would like to answer you, it will be easier for them to copy the error and perform searches.

In general, questions for help should be asked on StackOverflow.

It seems that you have a dev depency in composer that should have been in your regular dependencies. If you believe this is caused by the package, let me know.

Pesulap commented 1 week ago

I'm sorry, I'm sending ` 11:33:52 ERROR [php] Warning: Undefined array key "_service_doctrine.orm.default_listeners.attach_entity_listeners" ["exception" => ErrorException { …}] {"message":"Uncaught Error: Method name must be a string","context":{"exception":{"class":"Error","message":"Method name must be a string","code":0,"file":"/app/vendor/symfony/doctrine-bridge/ContainerAwareEventManager.php:63"}},"level":500,"level_name":"CRITICAL","channel":"php","datetime":"2024-10-17T11:33:52.140844+02:00","extra":{}} 11:33:52 CRITICAL [php] Uncaught Error: Method name must be a string ["exception" => Error { …}]

In ContainerAwareEventManager.php line 63:

Method name must be a string
`

!! !! Warning: Undefined array key "_service_doctrine.orm.default_listeners.attach_entity_listeners" in /app/vendor/symfony/doctrine-bridge/ContainerAwareEventManager.php on line 63 !! !! Fatal error: Uncaught Error: Method name must be a string in /app/vendor/symfony/doctrine-bridge/ContainerAwareEventManager.php:63 !! Stack trace: !! #0 /app/vendor/doctrine/orm/src/Mapping/ClassMetadataFactory.php(250): Symfony\Bridge\Doctrine\ContainerAwareEventManager->dispatchEvent('loadClassMetada...', Object(Doctrine\ORM\Event\LoadClassMetadataEventArgs)) !! #1 /app/vendor/doctrine/doctrine-bundle/src/Mapping/ClassMetadataFactory.php(18): Doctrine\ORM\Mapping\ClassMetadataFactory->doLoadMetadata(Object(Doctrine\ORM\Mapping\ClassMetadata), NULL, false, Array) !! #2 /app/vendor/doctrine/persistence/src/Persistence/Mapping/AbstractClassMetadataFactory.php(343): Doctrine\Bundle\DoctrineBundle\Mapping\ClassMetadataFactory->doLoadMetadata(Object(Doctrine\ORM\Mapping\ClassMetadata), NULL, false, Array) !! #3 /app/vendor/doctrine/persistence/src/Persistence/Mapping/AbstractClassMetadataFactory.php(207): Doctrine\Persistence\Mapping\AbstractClassMetadataFactory->loadMetadata('Lexik\\Bundle\\Tr...') !! #4 /app/vendor/doctrine/orm/src/EntityManager.php(329): Doctrine\Persistence\Mapping\AbstractClassMetadataFactory->getMetadataFor('Lexik\\Bundle\\Tr...') !! #5 /app/vendor/lexik/translation-bundle/Storage/DoctrineORMStorage.php(64): Doctrine\ORM\EntityManager->getClassMetadata('Lexik\\Bundle\\Tr...') !! #6 /app/vendor/lexik/translation-bundle/EventDispatcher/GetDatabaseResourcesListener.php(25): Lexik\Bundle\TranslationBundle\Storage\DoctrineORMStorage->translationsTablesExist() !! #7 /app/vendor/symfony/event-dispatcher/EventDispatcher.php(246): Lexik\Bundle\TranslationBundle\EventDispatcher\GetDatabaseResourcesListener->onGetDatabaseResources(Object(Lexik\Bundle\TranslationBundle\EventDispatcher\Event\GetDatabaseResourcesEvent), 'Lexik\\Bundle\\Tr...', Object(Symfony\Component\EventDispatcher\EventDispatcher)) !! #8 /app/vendor/symfony/event-dispatcher/EventDispatcher.php(206): Symfony\Component\EventDispatcher\EventDispatcher::Symfony\Component\EventDispatcher\{closure}(Object(Lexik\Bundle\TranslationBundle\EventDispatcher\Event\GetDatabaseResourcesEvent), 'Lexik\\Bundle\\Tr...', Object(Symfony\Component\EventDispatcher\EventDispatcher)) !! #9 /app/vendor/symfony/event-dispatcher/EventDispatcher.php(56): Symfony\Component\EventDispatcher\EventDispatcher->callListeners(Array, 'Lexik\\Bundle\\Tr...', Object(Lexik\Bundle\TranslationBundle\EventDispatcher\Event\GetDatabaseResourcesEvent)) !! #10 /app/vendor/lexik/translation-bundle/Translation/Translator.php(28): Symfony\Component\EventDispatcher\EventDispatcher->dispatch(Object(Lexik\Bundle\TranslationBundle\EventDispatcher\Event\GetDatabaseResourcesEvent)) !! #11 /app/var/cache/prod/ContainerV5brtpS/App_KernelProdContainer.php(606): Lexik\Bundle\TranslationBundle\Translation\Translator->addDatabaseResources() !! #12 /app/var/cache/prod/ContainerV5brtpS/getLocaleProviderService.php(21): ContainerV5brtpS\App_KernelProdContainer::getLexikTranslation_TranslatorService(Object(ContainerV5brtpS\App_KernelProdContainer)) !! #13 /app/var/cache/prod/ContainerV5brtpS/App_KernelProdContainer.php(206): ContainerV5brtpS\getLocaleProviderService::do(Object(ContainerV5brtpS\App_KernelProdContainer), true) !! #14 /app/var/cache/prod/ContainerV5brtpS/getTranslatableEventSubscriberService.php(21): ContainerV5brtpS\App_KernelProdContainer->load('getLocaleProvid...') !! #15 /app/var/cache/prod/ContainerV5brtpS/App_KernelProdContainer.php(206): ContainerV5brtpS\getTranslatableEventSubscriberService::do(Object(ContainerV5brtpS\App_KernelProdContainer), true) !! #16 /app/vendor/symfony/dependency-injection/Container.php(390): ContainerV5brtpS\App_KernelProdContainer->load('getTranslatable...') !! #17 /app/vendor/symfony/dependency-injection/Argument/ServiceLocator.php(40): Symfony\Component\DependencyInjection\Container->getService('services', 'Knp\\DoctrineBeh...', 'getTranslatable...', true) !! #18 /app/vendor/symfony/doctrine-bridge/ContainerAwareEventManager.php(176): Symfony\Component\DependencyInjection\Argument\ServiceLocator->get('Knp\\DoctrineBeh...') !! #19 /app/vendor/symfony/doctrine-bridge/ContainerAwareEventManager.php(59): Symfony\Bridge\Doctrine\ContainerAwareEventManager->initializeListeners('loadClassMetada...') !! #20 /app/vendor/doctrine/orm/src/Mapping/ClassMetadataFactory.php(250): Symfony\Bridge\Doctrine\ContainerAwareEventManager->dispatchEvent('loadClassMetada...', Object(Doctrine\ORM\Event\LoadClassMetadataEventArgs)) !! #21 /app/vendor/doctrine/doctrine-bundle/src/Mapping/ClassMetadataFactory.php(18): Doctrine\ORM\Mapping\ClassMetadataFactory->doLoadMetadata(Object(Doctrine\ORM\Mapping\ClassMetadata), NULL, false, Array) !! #22 /app/vendor/doctrine/persistence/src/Persistence/Mapping/AbstractClassMetadataFactory.php(343): Doctrine\Bundle\DoctrineBundle\Mapping\ClassMetadataFactory->doLoadMetadata(Object(Doctrine\ORM\Mapping\ClassMetadata), NULL, false, Array) !! #23 /app/vendor/doctrine/persistence/src/Persistence/Mapping/AbstractClassMetadataFactory.php(207): Doctrine\Persistence\Mapping\AbstractClassMetadataFactory->loadMetadata('App\\Entity\\Esho...') !! #24 /app/vendor/doctrine/persistence/src/Persistence/Mapping/AbstractClassMetadataFactory.php(96): Doctrine\Persistence\Mapping\AbstractClassMetadataFactory->getMetadataFor('App\\Entity\\Esho...') !! #25 /app/vendor/doctrine/doctrine-bundle/src/CacheWarmer/DoctrineMetadataCacheWarmer.php(48): Doctrine\Persistence\Mapping\AbstractClassMetadataFactory->getAllMetadata() !! #26 /app/vendor/symfony/framework-bundle/CacheWarmer/AbstractPhpFileCacheWarmer.php(41): Doctrine\Bundle\DoctrineBundle\CacheWarmer\DoctrineMetadataCacheWarmer->doWarmUp('/app/var/cache/...', Object(Symfony\Component\Cache\Adapter\ArrayAdapter), '/app/var/cache/...') !! #27 /app/vendor/symfony/http-kernel/CacheWarmer/CacheWarmerAggregate.php(96): Symfony\Bundle\FrameworkBundle\CacheWarmer\AbstractPhpFileCacheWarmer->warmUp('/app/var/cache/...', '/app/var/cache/...') !! #28 /app/vendor/symfony/http-kernel/Kernel.php(542): Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerAggregate->warmUp('/app/var/cache/...', '/app/var/cache/...') !! #29 /app/vendor/symfony/http-kernel/Kernel.php(740): Symfony\Component\HttpKernel\Kernel->initializeContainer() !! #30 /app/vendor/symfony/http-kernel/Kernel.php(120): Symfony\Component\HttpKernel\Kernel->preBoot() !! #31 /app/src/Kernel.php(15): Symfony\Component\HttpKernel\Kernel->boot() !! #32 /app/vendor/symfony/framework-bundle/Console/Application.php(177): App\Kernel->boot() !! #33 /app/vendor/symfony/framework-bundle/Console/Application.php(69): Symfony\Bundle\FrameworkBundle\Console\Application->registerCommands() !! #34 /app/vendor/symfony/console/Application.php(167): Symfony\Bundle\FrameworkBundle\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput)) !! #35 /app/vendor/symfony/runtime/Runner/Symfony/ConsoleApplicationRunner.php(49): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput)) !! #36 /app/vendor/autoload_runtime.php(29): Symfony\Component\Runtime\Runner\Symfony\ConsoleApplicationRunner->run() !! #37 /app/bin/console(11): require_once('/app/vendor/aut...') !! #38 {main} !! thrown in /app/vendor/symfony/doctrine-bridge/ContainerAwareEventManager.php on line 63

Otherwise, yes, it's caused by the package, because if I removed it, everything works as it should. So the problem will be in the package, but for some reason only in the production version.

bartmcleod commented 1 week ago

@Pesulap Is the entire package maybe in the require-dev section of your composer.json?

Pesulap commented 1 week ago

here is my composer.json

"require": { "php": ">=8.2", "ext-ctype": "", "ext-iconv": "", "beberlei/doctrineextensions": "^1.3", "doctrine/annotations": "^1.0", "doctrine/dbal": "v3.8", "doctrine/doctrine-bundle": "2.13.0", "doctrine/doctrine-migrations-bundle": "^3.2", "doctrine/orm": "^2.11", "dukecity/command-scheduler-bundle": "^6.0", "friendsofsymfony/ckeditor-bundle": "^2.4", "gmostafa/php-graphql-client": "^1.13", "helios-ag/fm-elfinder-bundle": "^12.1", "knplabs/doctrine-behaviors": "dev-sf7.0 as 2.6.3", "lexik/translation-bundle": "^v7.1", "liip/imagine-bundle": "^2.7", "nelmio/cors-bundle": "^2.3", "phpdocumentor/reflection-docblock": "^5.3", "phpoffice/phpspreadsheet": "^1.29", "phpstan/phpdoc-parser": "^1.2", "psr/http-factory": "^1.0", "ramsey/uuid-doctrine": "^2.0", "sentry/sentry-symfony": "5.", "symfony/apache-pack": "^1.0", "symfony/asset": "7.1.", "symfony/console": "7.1.", "symfony/dotenv": "7.1.", "symfony/expression-language": "7.1.", "symfony/flex": "^2", "symfony/form": "7.1.", "symfony/framework-bundle": "7.1.", "symfony/http-client": "7.1.", "symfony/intl": "7.1.", "symfony/mailer": "7.1.", "symfony/mime": "7.1.", "symfony/monolog-bundle": "^3.1", "symfony/notifier": "7.1.", "symfony/process": "7.1.", "symfony/property-access": "7.1.", "symfony/property-info": "7.1.", "symfony/proxy-manager-bridge": "6.4.", "symfony/runtime": "7.1.", "symfony/security-bundle": "7.1.", "symfony/serializer": "7.1.", "symfony/string": "7.1.", "symfony/translation": "7.1.", "symfony/twig-bundle": "7.1.", "symfony/validator": "7.1.", "symfony/web-link": "7.1.", "symfony/webpack-encore-bundle": "^2", "symfony/yaml": "7.1.", "symfonycasts/reset-password-bundle": "^1.13", "symfonycasts/verify-email-bundle": "^1.10", "twig/extra-bundle": "^3.7", "twig/intl-extra": "^3.7", "twig/twig": "^2.12|^3.0", "vich/uploader-bundle": "^2" }, "require-dev": { "roave/security-advisories": "dev-latest", "phpunit/phpunit": "^9.5", "symfony/browser-kit": "7.1.", "symfony/css-selector": "7.1.", "symfony/debug-bundle": "7.1.", "symfony/maker-bundle": "^1.0", "symfony/phpunit-bridge": "^6.0", "symfony/stopwatch": "7.1.", "symfony/web-profiler-bundle": "7.1." },

bartmcleod commented 1 week ago

@Pesulap I quickly tried during my lunch break, but I can't currently install sf 7.1, so it will require more effort, sorry.

bartmcleod commented 1 week ago

@Pesulap I took the time to try it out with Symfony 7.1.5 and it can clear the cache just fine. As you can see I am using dev-master for Lexik.

My composer.json

{
    "type": "project",
    "license": "proprietary",
    "minimum-stability": "stable",
    "prefer-stable": true,

    "require": {
        "php": ">=8.2",
        "ext-ctype": "*",
        "ext-iconv": "*",
        "doctrine/doctrine-bundle": "^2.11",
        "doctrine/orm": "^2.17",
        "lexik/translation-bundle": "dev-master",
        "symfony/asset": "7.0.*",
        "symfony/console": "7.0.*",
        "symfony/dotenv": "7.0.*",
        "symfony/flex": "^2",
        "symfony/form": "7.0.*",
        "symfony/framework-bundle": "7.0.*",
        "symfony/runtime": "7.0.*",
        "symfony/security-csrf": "7.0.*",
        "symfony/translation": "7.0.*",
        "symfony/twig-bundle": "7.0.*",
        "symfony/validator": "^7.0",
        "symfony/yaml": "7.0.*"
    },
    "config": {
        "allow-plugins": {
            "php-http/discovery": true,
            "symfony/flex": true,
            "symfony/runtime": true
        },
        "sort-packages": true
    },
    "autoload": {
        "psr-4": {
            "App\\": "src/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "App\\Tests\\": "tests/"
        }
    },
    "replace": {
        "symfony/polyfill-ctype": "*",
        "symfony/polyfill-iconv": "*",
        "symfony/polyfill-php72": "*",
        "symfony/polyfill-php73": "*",
        "symfony/polyfill-php74": "*",
        "symfony/polyfill-php80": "*",
        "symfony/polyfill-php81": "*",
        "symfony/polyfill-php82": "*"
    },
    "scripts": {
        "auto-scripts": {
            "cache:clear": "symfony-cmd",
            "assets:install %PUBLIC_DIR%": "symfony-cmd"
        },
        "post-install-cmd": [
            "@auto-scripts"
        ],
        "post-update-cmd": [
            "@auto-scripts"
        ]
    },
    "conflict": {
        "symfony/symfony": "*"
    },
    "extra": {
        "symfony": {
            "allow-contrib": false,
            "require": "7.1.*"
        }
    }

}
Pesulap commented 1 week ago

Thank you for your response,

so I keep looking, and it seems the problem is at the docker level. Which I had no idea it could be. If I install mysql:8.0.40 , the cache clearing will pass, but if I use mysql:8.4.3 or just mysql:8 image, it fails.

Even if it doesn't make sense :/ It could be more likely a version of PHP

bartmcleod commented 1 week ago

@Pesulap You would have to step through it with a debugger to find the exact problem. The thing is that any exception that will be thrown during the collection of the callables (?) array will cause this. Literally any exception. So it is very likely that a small incompatibility in the version of your database server can cause this.

Instead of the expected "_service_doctrine.orm.default_listeners.attach_entity_listeners", there is an entry called "exception" and the value is a the exception itself, instead of the expected string.

bartmcleod commented 1 week ago

I will close this, as it is a problem outside the Lexik translation package.