Skip to content
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

override_url breaks setup #1340

Closed
dbu opened this issue May 8, 2021 · 9 comments
Closed

override_url breaks setup #1340

dbu opened this issue May 8, 2021 · 9 comments

Comments

@dbu
Copy link
Member

dbu commented May 8, 2021

i am struggling getting dbal to work in a docker container. i have

$ env
DATABASE_URL="pdo-mysql://user:pass@otherserver:3306/databasename?serverVersion=5.7"
HOSTNAME=28e3e5d4d314
PHP_VERSION=8.0.5
PHP_INI_DIR=/usr/local/etc/php
GPG_KEYS=...
PHP_LDFLAGS=-Wl,-O1 -pie
PWD=/var/www/html
HOME=/var/www
APP_ENV=prod
PHP_SHA256=5dd358b35ecd5890a4f09fb68035a72fe6b45d3ead6999ea95981a107fd1f2ab
PHPIZE_DEPS=autoconf            dpkg-dev                file            g++             gcc             libc-dev                make            pkg-config              re2c
TERM=xterm
PHP_URL=https://www.php.net/distributions/php-8.0.5.tar.xz
PHP_EXTRA_CONFIGURE_ARGS=--enable-fpm --with-fpm-user=www-data --with-fpm-group=www-data --disable-cgi
SHLVL=1
PHP_CFLAGS=-fstack-protector-strong -fpic -fpie -O2 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
PHP_ASC_URL=https://www.php.net/distributions/php-8.0.5.tar.xz.asc
PHP_CPPFLAGS=-fstack-protector-strong -fpic -fpie -O2 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
APP_SECRET=...

the config/packages/doctrine.yaml file has

doctrine:
    dbal:
        override_url: false
        url: '%env(resolve:DATABASE_URL)%'

i dump the $dsn at vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php and it is
mysql:host=localhost;dbname=pdo-mysql://user:pass@otherserver:3306/databasename;charset=utf8mb4;

i tried setting override_url to false, but that made no difference.

i first had just mysql, but then tried pdo-mysql to see if it makes a difference. it made no difference.

what is extra weird is that if i run the console and define DATABASE_URL again, it is picked up correctly:

$ DATABASE_URL="pdo-mysql://user:pass@otherserver:3306/databasename?serverVersion=5.7" bin/console doctrine:migrations:migrate

from the fact that the wrong connection dsn does mention my things, i know that the env variable is not simply unseen, but it gets mixed up with some defaults. any ideas?

@ostrolucky
Copy link
Member

Description is all over the place. What's the issue? And why is title saying override_url breaks setup when in description you say you experience issue no matter the override_url value?

@dbu
Copy link
Member Author

dbu commented May 9, 2021

sorry for the confusing report. i started writing, tried more stuff and continued writing. the thing that confused me is how my DATABASE_URL got taken as only the database name and the default host etc are used for the connection information.

i suspected that #1290 would be to blame. however, after a nights sleep, i tried with doctrine-bundle 2.2.4 and it is not about this. looking closely at everything again, i noticed that aparently the way i set my env variable in docker with an env_file it keeps the quotes in the variable. (visible in the env output i copy-pasted, but i did not notice them). if i remove the quotes in my env file, things work as expected. (when setting the variable on the cli, the quotes get eaten by bash). so my issue is fixed.


however, to help prevent others running into the same problem: i am confused as to why the quoted DATABASE_URL is taken as database name with the quotes removed. is that by design? https://www.doctrine-project.org/projects/doctrine-dbal/en/current/reference/configuration.html#connecting-using-a-url does not mention that. wouldn't it make sense to either complain about the extra quotes or strip them so that the string is parsed correctly?

btw, on my hunt for documentation, i stumbled over https://symfony.com/doc/current/reference/configuration/doctrine.html#doctrine-dbal-configuration which claims that the url overwrites the individual settings. since 2.3 when override_url is set, it is the opposite, right? if you confirm, i will do a pull request on the symfony doc to add explanation about override_url.

@nicolas-grekas
Copy link
Member

nicolas-grekas commented May 9, 2021

We are likely to deprecate override_url in 2.4, see #1335
Doc PR welcome indeed!

@dbu
Copy link
Member Author

dbu commented May 9, 2021

do you have any input on the quote handling of DATABASE_URL? i'd love to clarify that in the dbal documentation. if the generated $dsn would just have my bogus DATABASE_URL including the quotes, i'd say it is just something that doctrine does not handle. but the quotes got stripped at some point, but aparently too late, which i find confusing.

@dbu
Copy link
Member Author

dbu commented May 9, 2021

@nicolas-grekas doc PR for status quo with DoctrineBundle 2.3: symfony/symfony-docs#15321

@stof
Copy link
Member

stof commented May 10, 2021

@dbu IIRC, the Docker handling of env files does not parse them using the Bash rules, so they don't support the same quoting that bash. Symfony DotEnv explicitly supports a format that is compatible with using the file as source .env

@dbu
Copy link
Member Author

dbu commented May 10, 2021

yeah, it seems so that Docker does put them literal. but it is confusing to me why the env variable (including quotes) DATABASE_URL="pdo-mysql://user:pass@otherserver:3306/databasename?serverVersion=5.7" leads to a $dsn of mysql:host=localhost;dbname=pdo-mysql://user:pass@otherserver:3306/databasename;charset=utf8mb4; - i would have expected it to be mysql:host=localhost;dbname="pdo-mysql://user:pass@otherserver:3306/databasename?serverVersion=5.7";charset=utf8mb4;

something did take away the " (and also the serverVersion parameter) - i wonder why it did that and if it does it if it could not happen earlier or complain when there is an extra layer of quotes.

@stof
Copy link
Member

stof commented May 10, 2021

@dbu this thing might at least partially be PHP's parse_url: https://3v4l.org/0LPbh

Also, serverVersion is not something that end up in the dsn (and here, it is still parsed in the query string)

@dbu
Copy link
Member Author

dbu commented May 10, 2021

wow, that parse_url is not what i would have expected :-O

okay, if we don't actively do something about it in the bundle i guess its fine to keep not doing. i thought we somehow actively remove the quotes but too late... lets leave as is and hope other people don't confuse docker env variable logic with bash logic like i did...

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

No branches or pull requests

4 participants