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

Environment variables ignored if the value provided in the configuration file #5960

Closed
AlexSkrypnyk opened this issue Apr 19, 2024 · 2 comments

Comments

@AlexSkrypnyk
Copy link
Contributor

AlexSkrypnyk commented Apr 19, 2024

Describe the bug
Given $HOME/.drush/drush.yml file with the following content:

options:
  root: myroot
  uri: mysite.local

When I call

DRUSH_OPTIONS_URI=other.domain ./vendor/bin/drush st

Then I see the output

Drupal version : 10.1.4                                      
Site URI       : mysite.local

Expected behavior
Then I see the output

Drupal version : 10.1.4                                      
Site URI       : other.domain

Workaround
Is there another way to do the desired action?

System Configuration

Q A
Drush version? 12.5.11
Drupal version? 10.1
PHP version 8.1
OS? Mac

Additional information

The issue lies in Drush ConfigLocator. The constructor adds the user context after env context. consolidation/log's ConfigOverlay::findContext() looks up the contexts in reversed order hence the options.uri defined in /home/.drush/drush.yml (user context) supersedes the DRUSH_OPTIONS_URI var (env context).

In ConfigLocator::__contruct()

$this->config->addPlaceholder(self::DRUSH_CONTEXT);
if (!empty($envPrefix)) {
    $envConfig = new EnvConfig($envPrefix);
    $this->config->addContext(self::ENV_CONTEXT, $envConfig);
}
$this->config->addPlaceholder(self::USER_CONTEXT);

If I move USER_CONTEXT above ENV_CONTEXT the DRUSH_OPTIONS_URI will take precedence as expected.

sonnykt added a commit to sonnykt/drush that referenced this issue Apr 19, 2024
sonnykt added a commit to sonnykt/drush that referenced this issue Apr 19, 2024
…ided in the user configuration file.

On-behalf-of: @salsadigitalauorg <sonny.kieu@salsa.digital>
sonnykt added a commit to sonnykt/drush that referenced this issue Apr 24, 2024
On-behalf-of: @salsadigitalorgau <sonny.kieu@salsa.digital>
sonnykt added a commit to sonnykt/drush that referenced this issue Apr 24, 2024
On-behalf-of: @salsadigitalauorg <sonny.kieu@salsa.digital>
weitzman added a commit that referenced this issue Apr 29, 2024
…he user configuration file. (#5961)

* Issue #5960: Environment variables ignored if the value provided in the user configuration file.

On-behalf-of: @salsadigitalauorg <sonny.kieu@salsa.digital>

* Issue #5960: Updated unit test.

On-behalf-of: @salsadigitalauorg <sonny.kieu@salsa.digital>

---------

Co-authored-by: Moshe Weitzman <weitzman@tejasa.com>
@weitzman
Copy link
Member

weitzman commented May 1, 2024

Fixed in #5961

@weitzman weitzman closed this as completed May 1, 2024
@AlexSkrypnyk
Copy link
Contributor Author

This will be available in Drush 13. Not backported to Drush 12.

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

2 participants