Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Regression of YAML !php/const: prefix in Symfony v6.2.0-BETA2 config #48135

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
guillaumesmo opened this issue Nov 7, 2022 · 9 comments · Fixed by #48207
Closed

Regression of YAML !php/const: prefix in Symfony v6.2.0-BETA2 config #48135

guillaumesmo opened this issue Nov 7, 2022 · 9 comments · Fixed by #48207

Comments

@guillaumesmo
Copy link
Contributor

Symfony version(s) affected

v6.2.0-BETA2

Description

In Symfony v6.2.0-BETA2, I'm unable to use the YAML !php/const: prefix in doctrine config

Previously, you could do this:

doctrine:
    dbal:
        options:
            !php/const:PDO::MYSQL_ATTR_INIT_COMMAND: SET max_execution_time=60000

In Symfony v6.2.0-BETA2, I get the following error:
Invalid type for path "doctrine.dbal.connections.default.options". Expected "array", but got "Symfony\Component\Yaml\Tag\TaggedValue"

Although there's a simple workaround I wonder if it doesn't affect configuration in other places/cases, which is why I report it

How to reproduce

Add the following config in doctrine.yaml:

doctrine:
    dbal:
        options:
            !php/const:PDO::MYSQL_ATTR_INIT_COMMAND: SET max_execution_time=60000

In Symfony v6.2.0-BETA2, I get the following error:
Invalid type for path "doctrine.dbal.connections.default.options". Expected "array", but got "Symfony\Component\Yaml\Tag\TaggedValue"

Workaround is to use the constant value instead

doctrine:
    dbal:
        options:
            1002: SET max_execution_time=60000

Possible Solution

No response

Additional Context

No response

@stof
Copy link
Member

stof commented Nov 7, 2022

A regression compared to which version ?

Note that the right syntax is !php/const PDO::MYSQL_ATTR_INIT_COMMAND, not !php/const:PDO::MYSQL_ATTR_INIT_COMMAND

@guillaumesmo
Copy link
Contributor Author

guillaumesmo commented Nov 7, 2022

it works indeed with !php/const PDO::MYSQL_ATTR_INIT_COMMAND

somehow !php/const:PDO::MYSQL_ATTR_INIT_COMMAND has been working at least since 5.1 until 6.1, but if that is not intended to work like that, I guess we can close this ticket

https://symfony.com/blog/new-in-symfony-3-2-php-constants-in-yaml-files eg uses both !php/const: and !php/const in the same article

@derrabus
Copy link
Member

derrabus commented Nov 7, 2022

uses both !php/const: and !php/const in the same article

Yes, with a comment explaining that on Symfony 3.4 onwards, you should use the notation without :.

@guillaumesmo
Copy link
Contributor Author

guillaumesmo commented Nov 7, 2022

Thanks, my bad

However it is strange that support for !php/const: (deprecated in 3.x I suppose) is dropped in Symfony 6.2, I would rather expect that in Symfony 4.0 or any future major version

@derrabus
Copy link
Member

derrabus commented Nov 7, 2022

However it is strange that support for !php/const: (deprecated in 3.x I suppose) is dropped in Symfony 6.2, I would rather expect that in Symfony 4.0 or any future major version

Yeah, me too. If this notation has really still worked in 6.1 and possibly 5.x as well, we should consider treating this issue as a regression.

@xabbuh
Copy link
Member

xabbuh commented Nov 7, 2022

@guillaumesmo Can you create a small example application using 6.1 where this works?

@guillaumesmo guillaumesmo changed the title Regression of YAML !php/const: prefix in Symfony v6.2.0-BETA2 doctrine configuration Regression of YAML !php/const: prefix in Symfony v6.2.0-BETA2 config Nov 7, 2022
@guillaumesmo
Copy link
Contributor Author

guillaumesmo commented Nov 7, 2022

git clone [email protected]:guillaumesmo/symfony-issue-48135.git
cd symfony-issue-48135
symfony serve
curl http://127.0.0.1:8000

In this example I used the prefix in a simple parameter, and it also fails there, so the issue is not limited to doctrine config.

parameters:
    test_params:
        !php/const:PHP_INT_SIZE: test

With Symfony 6.0/6.1 I get the following: {"8":"test"}

With Symfony 6.2-BETA2 I get this error: Fatal error: Uncaught Symfony\Component\Yaml\Exception\ParseException: Mapping values are not allowed in multi-line blocks at line 16 (near "!php/const:PHP_INT_SIZE: test").

@xabbuh xabbuh reopened this Nov 11, 2022
@GromNaN
Copy link
Member

GromNaN commented Nov 11, 2022

It should be possible to improve the exception message, to suggest the correct syntax.

@maxbeckers
Copy link
Contributor

@GromNaN it is deprecated since 3.x ... but now it's a bc break. Shouldn't we now support the : until version 7.0?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants