EasyAdminBundle icon indicating copy to clipboard operation
EasyAdminBundle copied to clipboard

Pretty URLs loads YAML configurations on each request

Open Axel29 opened this issue 9 months ago • 2 comments

Describe the bug

When a bundle requires some environemnt variables to be set, if these requirements are not matched, every Symfony commands / admin page will be broken because of the Pretty URLs loading every config files.

To Reproduce

  1. Install for example the stripe/stripe-php package with Composer
  2. Activate the pretty URLs
  3. Do not configure the api_key
  4. Create a custom Factory and declare it in the services.yaml file like this:
  App\DependencyInjection\Factory\PaymentServiceProviderFactory: ~
  App\DependencyInjection\PaymentServiceProviderInterface:
    factory: ['@App\DependencyInjection\Factory\PaymentServiceProviderFactory', 'getPaymentServiceProvider']
  1. Create the Factory class such as this:
<?php

declare(strict_types=1);

namespace App\DependencyInjection\Factory;

use Stripe\StripeClient;

readonly class PaymentServiceProviderFactory
{
    private StripeClient $stripeClient;

    public function __construct(string $apiKey)
    {
        $this->stripeClient = new StripeClient($apiKey);
    }
}
  1. Run any command like php bin/console cache:clear or access the admin

Additional context

This seems to be the same issue as #6506 but it was marked as fixed, even though I tried using a dd('here'); in the \Symfony\Component\Routing\Loader\YamlFileLoader::load method and still gets it on every page loaded in the admin.

Screenshot of the error when loading an admin page:

Image

Axel29 avatar Mar 17 '25 17:03 Axel29

hi @javiereguiluz I am facing exactly the same issue as described by @Axel29 - I would be happy to help, but am not really sure where to begin / what to look for, can you possibly give a hint? 🤔

There also seem to be an issue in the way the dependency injections are applied: in one of my projects I needed to set a default value for some class attributes which were not needed at all before activating the pretty URLs.

jmariller avatar Mar 20 '25 14:03 jmariller

New issue found related: doctrine migrations are not launched (with the command symfony console doctrine:migrations:migrate --allow-no-migration --no-interaction -vvv) because of the cache warmup on Kubernetes servers.

If a Service tries to load entities from the constructor method, it will trigger an Exception..

Exception trace:
  at /var/www/symfony/vendor/doctrine/dbal/src/Driver/PDO/Exception.php:24
 Doctrine\DBAL\Driver\PDO\Exception::new() at /var/www/symfony/vendor/doctrine/dbal/src/Driver/PDO/Connection.php:76
 Doctrine\DBAL\Driver\PDO\Connection->query() at /var/www/symfony/vendor/doctrine/dbal/src/Connection.php:1106
 Doctrine\DBAL\Connection->executeQuery() at /var/www/symfony/vendor/doctrine/orm/src/Persisters/Entity/BasicEntityPersister.php:972
 Doctrine\ORM\Persisters\Entity\BasicEntityPersister->loadAll() at /var/www/symfony/vendor/doctrine/orm/src/EntityRepository.php:224
 Doctrine\ORM\EntityRepository->findBy() at /var/www/symfony/vendor/doctrine/orm/src/EntityRepository.php:206
 Doctrine\ORM\EntityRepository->findAll() at /var/www/symfony/src/Service/MetafieldTypeResolver.php:96
 App\Service\MetafieldTypeResolver->initMetafieldDefinitionsCache() at /var/www/symfony/src/Service/MetafieldTypeResolver.php:27
 App\Service\MetafieldTypeResolver->__construct() at /var/www/symfony/var/cache/prod/ContainerEqIK0b9/App_KernelProdDebugContainer.php:14031
 ContainerEqIK0b9\App_KernelProdDebugContainer::getMetafieldTypeResolverService() at /var/www/symfony/var/cache/prod/ContainerEqIK0b9/App_KernelProdDebugContainer.php:12891
 ContainerEqIK0b9\App_KernelProdDebugContainer::getProductServiceService() at /var/www/symfony/var/cache/prod/ContainerEqIK0b9/App_KernelProdDebugContainer.php:12579
 ContainerEqIK0b9\App_KernelProdDebugContainer::getSynchronizeService2Service() at /var/www/symfony/var/cache/prod/ContainerEqIK0b9/App_KernelProdDebugContainer.php:12383
 ContainerEqIK0b9\App_KernelProdDebugContainer::getFixOrphansServiceService() at /var/www/symfony/var/cache/prod/ContainerEqIK0b9/App_KernelProdDebugContainer.php:13639
 ContainerEqIK0b9\App_KernelProdDebugContainer::getBulkOperationServiceService() at /var/www/symfony/var/cache/prod/ContainerEqIK0b9/App_KernelProdDebugContainer.php:460
 ContainerEqIK0b9\App_KernelProdDebugContainer::getBulkOperationCrudControllerService() at /var/www/symfony/var/cache/prod/ContainerEqIK0b9/App_KernelProdDebugContainer.php:15413
 ContainerEqIK0b9\App_KernelProdDebugContainer::ContainerEqIK0b9\{closure}() at /var/www/symfony/vendor/easycorp/easyadmin-bundle/src/Router/AdminRouteGenerator.php:133
 EasyCorp\Bundle\EasyAdminBundle\Router\AdminRouteGenerator->generateAdminRoutes() at /var/www/symfony/vendor/easycorp/easyadmin-bundle/src/Router/AdminRouteGenerator.php:78
 EasyCorp\Bundle\EasyAdminBundle\Router\AdminRouteGenerator->generateAll() at /var/www/symfony/vendor/easycorp/easyadmin-bundle/src/Router/AdminRouteLoader.php:52
 EasyCorp\Bundle\EasyAdminBundle\Router\AdminRouteLoader->load() at /var/www/symfony/vendor/symfony/config/Loader/FileLoader.php:146
 Symfony\Component\Config\Loader\FileLoader->doImport() at /var/www/symfony/vendor/symfony/config/Loader/FileLoader.php:98
 Symfony\Component\Config\Loader\FileLoader->import() at /var/www/symfony/vendor/symfony/routing/Loader/YamlFileLoader.php:214
 Symfony\Component\Routing\Loader\YamlFileLoader->parseImport() at /var/www/symfony/vendor/symfony/routing/Loader/YamlFileLoader.php:99
 Symfony\Component\Routing\Loader\YamlFileLoader->load() at /var/www/symfony/vendor/symfony/config/Loader/FileLoader.php:167
 Symfony\Component\Config\Loader\FileLoader->doImport() at /var/www/symfony/vendor/symfony/config/Loader/FileLoader.php:87
 Symfony\Component\Config\Loader\FileLoader->import() at /var/www/symfony/vendor/symfony/routing/Loader/Configurator/RoutingConfigurator.php:45
 Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator->import() at /var/www/symfony/vendor/symfony/framework-bundle/Kernel/MicroKernelTrait.php:79
 App\Kernel->configureRoutes() at /var/www/symfony/vendor/symfony/framework-bundle/Kernel/MicroKernelTrait.php:213
 App\Kernel->loadRoutes() at /var/www/symfony/vendor/symfony/routing/Loader/ObjectLoader.php:55
 Symfony\Component\Routing\Loader\ObjectLoader->load() at /var/www/symfony/vendor/symfony/config/Loader/DelegatingLoader.php:37
 Symfony\Component\Config\Loader\DelegatingLoader->load() at /var/www/symfony/vendor/symfony/framework-bundle/Routing/DelegatingLoader.php:67
 Symfony\Bundle\FrameworkBundle\Routing\DelegatingLoader->load() at /var/www/symfony/vendor/symfony/framework-bundle/Routing/Router.php:65
 Symfony\Bundle\FrameworkBundle\Routing\Router->getRouteCollection() at /var/www/symfony/vendor/easycorp/easyadmin-bundle/src/Cache/CacheWarmer.php:43
 EasyCorp\Bundle\EasyAdminBundle\Cache\CacheWarmer->warmUp() at /var/www/symfony/vendor/symfony/http-kernel/CacheWarmer/CacheWarmerAggregate.php:108
 Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerAggregate->warmUp() at /var/www/symfony/vendor/symfony/http-kernel/Kernel.php:554
 Symfony\Component\HttpKernel\Kernel->initializeContainer() at /var/www/symfony/vendor/symfony/http-kernel/Kernel.php:772
 Symfony\Component\HttpKernel\Kernel->preBoot() at /var/www/symfony/vendor/symfony/http-kernel/Kernel.php:126
 Symfony\Component\HttpKernel\Kernel->boot() at /var/www/symfony/vendor/symfony/framework-bundle/Console/Application.php:190
 Symfony\Bundle\FrameworkBundle\Console\Application->registerCommands() at /var/www/symfony/vendor/symfony/framework-bundle/Console/Application.php:72
 Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /var/www/symfony/vendor/symfony/console/Application.php:175
 Symfony\Component\Console\Application->run() at /var/www/symfony/vendor/symfony/runtime/Runner/Symfony/ConsoleApplicationRunner.php:49
 Symfony\Component\Runtime\Runner\Symfony\ConsoleApplicationRunner->run() at /var/www/symfony/vendor/autoload_runtime.php:29
 require_once() at /var/www/symfony/bin/console:11

Axel29 avatar Mar 31 '25 16:03 Axel29