Skip to content

[4.1 BC Break][DI] Env placeholder defaulting to float now rejected for scalar config node #27455

Closed
@Majkl578

Description

@Majkl578

Symfony version(s) affected: 4.1.0

Description
Symfony 4.1.0 introduced validation of env vars in #23888. This breaks env defaults defined as parameters directly in YAML config for seemingly incompatible types, i.e. env defaulting to float value while node is declared as scalarNode (float is scalar too btw).

In ValidateEnvPlaceholdersPass.php line 54:
                                                                                                              
  [Symfony\Component\DependencyInjection\Exception\LogicException]                                            
  Invalid type for env parameter "env(ABC)". Expected "string", but got "float".

How to reproduce

This is based on real configuration of SncRedisBundle which now suffers from this BC break.

Have a bundle with DI configuration having a scalar config node as such:

...
->arrayNode('options')
    ->children()
        ->scalarNode('profile')->defaultValue('default')

Then configured using YAML like this:

parameters:
    env(REDIS_PROFILE): 3.2

snc_redis:
    clients:
        default:
            type: predis
            alias: default
            dsn: '%env(REDIS_DSN)%'
            options:
                profile: '%env(REDIS_PROFILE)%'

Since options.profile is defined as scalarNode(), default value 3.2 (being a float) is rejected and exception above is thrown.

Additional context

Exception trace:
 Symfony\Component\DependencyInjection\Compiler\ValidateEnvPlaceholdersPass->process() at vendor/symfony/dependency-injection/Compiler/Compiler.php:95
 Symfony\Component\DependencyInjection\Compiler\Compiler->compile() at vendor/symfony/dependency-injection/ContainerBuilder.php:736
 Symfony\Component\DependencyInjection\ContainerBuilder->compile() at vendor/symfony/http-kernel/Kernel.php:513
 Symfony\Component\HttpKernel\Kernel->initializeContainer() at vendor/symfony/http-kernel/Kernel.php:125
 Symfony\Component\HttpKernel\Kernel->boot() at vendor/symfony/framework-bundle/Console/Application.php:64
 Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at vendor/symfony/console/Application.php:143
 Symfony\Component\Console\Application->run() at bin/console:37

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions