Skip to content

cache:clear not working in PROD after renaming a variable in .env #59279

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
ThomasLandauer opened this issue Dec 21, 2024 · 3 comments
Closed

Comments

@ThomasLandauer
Copy link
Contributor

Symfony version(s) affected

7.2.1

Description

In Symfony 7.1, I had a variable named MAILER_DSN in my .env.
I now renamed it to FOO_MAILER_DSN and upgraded to Symfony 7.2. This worked fine on my DEV machine.
When deploying to PROD, I did (as recommended at https://symfony.com/doc/current/deployment.html#d-clear-your-symfony-cache)

APP_ENV=prod APP_DEBUG=0 php bin/console cache:clear

And got:

In EnvVarProcessor.php line 221:
Environment variable not found: "MAILER_DSN".

So I deleted the cache folder manually:

rm -rf var/cache/prod/*

And then everything was fine:

APP_ENV=prod APP_DEBUG=0 php bin/console cache:clear

Gave me the expected:

// Clearing the cache for the prod environment with debug false
[OK] Cache for the "prod" environment (debug=false) was successfully cleared.

How to reproduce

See above

Possible Solution

I already suggested to mention the manual way (rm ...) on the deployment page: symfony/symfony-docs#19836

So this is now the second issue with cache:clear I'm running into while deploying.

Additional Context

No response

@maximecolin
Copy link
Contributor

maximecolin commented Dec 23, 2024

Hello. I think this is the normal and expected behavior. bin/console cache:clear is a console command, so it must boot the kernel in order to work. And to boot the kernel, it will use the cached container, which require all env vars. If you rename a variable in the .env, the container in the cache will still need the previous variable.

In dev environnement it works because the container is rebuilt a each request / command exec, so it doesn't try to boot the cached container with the old env var.

I think the proper way to rename an env var is to push the new variable in production, keeping the old one, and then remove it in a second time.

@nicolas-grekas
Copy link
Member

Maxime is right.
We might also wonder why accessing the env var is needed at this stage. Not sure it's legit.

@GromNaN
Copy link
Member

GromNaN commented Dec 23, 2024

The same kind of error occurs when updating packages that no longer have the code corresponding to the cache.
Perhaps we need a special system for the cache:clear command.

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

No branches or pull requests

5 participants