Symfony 3.2.1 removes underscore from yml file value

186 views Asked by At

I tried to upgrade from Symfony 3.1.8 to 3.2.1 using composer. During the cache clear I received an error stating

An exception occured in driver: SQLSTATE[HY000] [1045] Access denied for user '########'@'IpAddress' (using password: YES)

however my database user name should be #######_#, notice the underscore in the second to last character position. Looking in the parameter.yml file I found that my database_user had been changed to remove the _ from the username (the underscore was stripped). I then added back my underscore, deleted the dev cache, and tried the application again. I received the same error as before.

Since composer also updated doctrine and the FOSuser bundle at the same time I reverted the update and went back to my prior configuration by reverting my composer.lock file. I then ran my Symfony application again in the version 3.1.8 and it worked fine.

To isolate the problem further I used composer and upgraded ONLY symfony from 3.1.8 to 3.2.1. The upgrade produced errors at the cache clear with the above error message, and in my parameters.yml file my database_user again had the underscore removed from the username. I re-inserted the underscore, however I continue to get the error messages:

An exception occured in driver: SQLSTATE[HY000] [1045] Access denied for user '########'@'IpAddress' (using password: YES)

If I add a letter to the end of my database_user so it is "#######_#a" the error message shows the _

An exception occured in driver: SQLSTATE[HY000] [1045] Access denied for user '#######_#a'@'IpAddress' (using password: YES)

If I then delete the letter the error message reverts to no underscore

An exception occured in driver: SQLSTATE[HY000] [1045] Access denied for user '########'@'IpAddress' (using password: YES)

This leads me to believe that some change in Symfony between 3.1.8 and 3.2.1 strip underscores from the database_user in the parameters.yml file. Unfortunately I am not skilled enough to figure out where that code may be.

1

There are 1 answers

0
MEmerson On BEST ANSWER

With help from github and a bit of reading I found that this is related to changes in how numeric values are handled in Symfony 3.1 (Blog Post). They now automatically strip underscore characters from all number values in yml files.

However in my case my username (provided by my web hosting company) was all numbers with an underscore in the second to last character and should be parsed as a string. This now gets interpreted by Symfony (in compliance with the YAML specifications) as a number and the underscore is stripped.

To solve this I simply added quotes around my username in the yml file and Symfony started handling the value correctly and I was able to run my application.