APP_KEY cant be set with key:generate when APP_KEY is already set in the environment#58340
Closed
nckrtl wants to merge 1 commit intolaravel:12.xfrom
Closed
APP_KEY cant be set with key:generate when APP_KEY is already set in the environment#58340nckrtl wants to merge 1 commit intolaravel:12.xfrom
nckrtl wants to merge 1 commit intolaravel:12.xfrom
Conversation
This test file tests the key:generate command. The second test test_key_generate_updates_env_file_even_when_app_key_exists_in_environment demonstrates that APP_KEY won't be set when APP_KEY has already been set in the environment, which is unexpected. Even if this is expected behaviour at least a proper error message should be shown. This is especially useful nowadays for LLMs to understand why key generation failed and come up with a workaround like using env -i (forcing empty environment)
Member
|
PR to correct error message welcome! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Consider this PR a bug report. I'm unsure yet what an elegant fix would be or if its intended behavior.
When running
php artisan key:generatewhileAPP_KEYhas already been set in the environment theAPP_KEYwon't be set and a misleading error message "Unable to set application key. No APP_KEY variable was found in the .env file." will be shown.You can also reproduce this on a mac or linux machine:
export APP_KEY=abcon the command line.php artisan key:generateinside the application.unset APP_KEYon the command line, and thekey:generatecommand will succeed.This issue also occurs when generating Laravel apps through jobs with Horizon as the
APP_KEYwill be set in the environment when jobs are being processed.If this is expected behavior then at least a proper error message should be shown. Especially for LLMs this would be helpful.
I provided a couple of tests where
test_key_generate_updates_env_file_even_when_app_key_exists_in_environmentdemonstrates the the current behavior and fails.