Skip to content

SF v4.2.1 env key processor error: 'Invalid type for path "doctrine.dbal.connections.default.default_table_options.dbname". Expected one of "bool", "int", "float", "string", but got one of "bool", "int", "float", "string", "array".' #29576

Closed
@ghost

Description

Following the example at

#27157

trying to get Symfony 4.2's new "env(key:FOO:BAR)" key processor working, it FAILS with error

'Invalid type for path "doctrine.dbal.connections.default.default_table_options.dbname". Expected one of "bool", "int", "float", "string", but got one of "bool", "int", "float", "string", "array".'

Symfony version(s) affected: 4.2.1

cc: @nicolas-grekas

'Reproducer' at
https://github.com/gcos2/keyproc

Steps to reproduce

php -v
	PHP 7.3.0 (cli) (built: Dec  8 2018 22:42:21) ( NTS )
	Copyright (c) 1997-2018 The PHP Group
	Zend Engine v3.3.0-dev, Copyright (c) 1998-2018 Zend Technologies
	    with Zend OPcache v7.3.0-dev, Copyright (c) 1999-2018, by Zend Technologies

mkdir -p /tmp/DEBUG
cd       /tmp/DEBUG
composer create-project symfony/website-skeleton KEYPROC
cd KEYPROC

cat << EOF > /tmp/DEBUG/.secrets.json
{
    "dbname": "my_dbname",
    "dbuser": "my_dbuser",
    "dbpass": "my_dbpass"
}
EOF

cat << EOF > .env.local
DBSOCK='/var/run/mariadb/mariadb.sock'
EOF

cat << EOF > config/packages/doctrine.yaml
parameters:
    env(DATABASE_URL): ''
    env(SECRETS_FILE): '/tmp/DEBUG/.secrets.json'

doctrine:
    dbal:
        driver: 'pdo_mysql'
        server_version: 'mariadb-10.3.11'
        charset: utf8mb4
        default_table_options:
            charset: utf8mb4
            collate: utf8mb4_unicode_ci
            unix_socket: '%env(DBSOCK)%'
            dbname:   '%env(key:dbname:json:file:SECRETS_FILE)%'
            user:     '%env(key:dbuser:json:file:SECRETS_FILE)%'
            password: '%env(key:dbpass:json:file:SECRETS_FILE)%'
#           dbname:   'my_dbname'
#           user:     'my_dbuser'
#           password: 'my_dbpass'

    orm:
        auto_generate_proxy_classes: true
        naming_strategy: doctrine.orm.naming_strategy.underscore
        auto_mapping: true
        mappings:
            App:
                is_bundle: false
                type: annotation
                dir: '%kernel.project_dir%/src/Entity'
                prefix: 'App\Entity'
                alias: App
EOF

# create DB
mysqlshow my_dbname
	Database: my_dbname
	+--------+
	| Tables |
	+--------+
	+--------+

# TEST:FAIL
bin/console make:user
	In BaseNode.php line 524:

	  Invalid type for path "doctrine.dbal.connections.default.default_table_options.dbname".
	  Expected one of "bool", "int", "float", "string", but got one of "bool", "int", "float",
	   "string", "array".


git add -A
git commit -m "fail using key processor"

CHANGE config/packages/doctrine.yaml
#	            dbname:   '%env(key:dbname:json:file:SECRETS_FILE)%'
#	            user:     '%env(key:dbuser:json:file:SECRETS_FILE)%'
#	            password: '%env(key:dbpass:json:file:SECRETS_FILE)%'
	            dbname:   'my_dbname'
	            user:     'my_dbuser'
	            password: 'my_dbpass'

git add -A
git commit -m "OK *not* using key processor"

git remote add origin https://github.com/gcos2/keyproc.git
git push -u origin master

# TEST:OK
bin/console make:user
	 The name of the security user class (e.g. User) [User]:
	 >

	 Do you want to store user data in the database (via Doctrine)? (yes/no) [yes]:
	 >

	 Enter a property name that will be the unique "display" name for the user (e.g. email, username, uuid) [email]:
	 >

	 Will this app need to hash/check user passwords? Choose No if passwords are not needed or will be checked/hashed by some other system (e.g. a single sign-on server).

	 Does this app need to hash/check user passwords? (yes/no) [yes]:
	 >

	The newer Argon2i password hasher requires PHP 7.2, libsodium or paragonie/sodium_compat. Your system DOES support this algorithm.
	You should use Argon2i unless your production system will not support it.

	 Use Argon2i as your password hasher (bcrypt will be used otherwise)? (yes/no) [yes]:
	 >

	 created: src/Entity/User.php
	 created: src/Repository/UserRepository.php
	 updated: src/Entity/User.php
	 updated: config/packages/security.yaml


	  Success!


	 Next Steps:
	   - Review your new App\Entity\User class.
	   - Use make:entity to add more fields to your User entity and then run make:migration.
	   - Create a way to authenticate! See https://symfony.com/doc/current/security.html

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