drush icon indicating copy to clipboard operation
drush copied to clipboard

Drush 9 config:set : Can not create new config via cset, but it can in 8.x version

Open ken-cit opened this issue 7 years ago • 12 comments

Hi Weitzman,

Good day! I used to import a config yaml file into a remote site via cset command in drush 8.x version : cat $config_file | drush @alias cset $config_name --format=yaml --value=- -y It will update the config_name and create it if not exists. It's really cool and useful. But after I upgrade to Drush 9.5.2 version, I can't run this command that way any more, I found the config_name was been validated if exists first and also the config key was required. I think if user uses yaml format option, he might want to update whole config object but not only one key.

So is it possible to make the config key optional when using yaml format? And do not validate config_name just like Drush 8.x did?

Thanks in advance. Ken

ken-cit avatar Nov 22 '18 10:11 ken-cit

Instead of --format use --input-format. I'm still not sure this will work anymore though.

weitzman avatar Nov 25 '18 13:11 weitzman

Thanks for your reply. I've tried the --input-format option, and that's not the point. I checked the ConfigCommands.php file, see line:121-133 :

else { $confirmed = false; if ($config->isNew() && $this->io()->confirm(dt('!name config does not exist. Do you want to create a new config object?', ['!name' => $config_name]))) { $confirmed = true; } elseif ($new_key && $this->io()->confirm(dt('!key key does not exist in !name config. Do you want to create a new config key?', ['!key' => $key, '!name' => $config_name]))) { $confirmed = true; } elseif ($this->io()->confirm(dt('Do you want to update !key key in !name config?', ['!key' => $key, '!name' => $config_name]))) { $confirmed = true; } if ($confirmed && !\Drush\Drush::simulate()) { return $config->set($key, $data)->save(); } }

So the cset command will handler the config_name is new or is existing. The tag "@validate-config-name" in annotation (in line:78) checks config_name in advance, as a result, this command has no chance to create new config any more.

ken-cit avatar Nov 26 '18 03:11 ken-cit

So does your use case work if that annotation is removed?

weitzman avatar Nov 26 '18 11:11 weitzman

Yes, it works after change those code. Please kindly check out attachement.

fix-3793-cset_cannot_create_new_config-issue.txt

ken-cit avatar Nov 28 '18 09:11 ken-cit

Your new code looks good, but I'm hesitant to remove the key validation. In the normal use case of cset, that validation is very useful. I'm not sure what to suggest. If you can get the config file to the host (possibly using drush rsync), then drush config:import --partial would do the rest.

weitzman avatar Dec 01 '18 19:12 weitzman

I've also run into this, having been using the drush config-set command with Drush 8 to create a filter.format.restricted_html config_entity in order to work around an issue in another module, and now looking to move to Drush 9 and having no equivalent command... my first thought is to add a --force flag or something of the like, but given it already explicitly asks for confirmation before creating the new config, it feels like it would be duplicating the --no-interaction/-y option.

adam-vessey avatar May 02 '19 13:05 adam-vessey

I also ran into this. No way to add a non-existing config item, which is very annoying, as i worked with a hidden config setting that has no UI.

Checked in the source:

  • validation of the config name is implemented by looking up if the config already exists. (if anything, this should look up the schema. But let's leave that for a followup or not at all.)
  • there is an explicit confirmation of !name config does not exist. Do you want to create a new config object?

Given that, +1 for removing the "validation" and relying on the confirmation.

geek-merlin avatar Jul 05 '19 20:07 geek-merlin

PR #4118 works fine here for quite some time ;-).

geek-merlin avatar Sep 05 '19 16:09 geek-merlin

Is there any reason why this has returned back in Drush 10?

https://github.com/drush-ops/drush/blob/master/src/Drupal/Commands/config/ConfigCommands.php#L87

Because this behaviour of not being able to cset non-existing config appears to have returned in Drush 10.

[error] Config stage_file_proxy.settings does not exist Failed to run drush -r /var/www/html/web cset stage_file_proxy.settings origin https://example.com -y: exit status 1

welly avatar Jul 28 '20 08:07 welly

I'm also looking for a way to import single config files with Drush 10. Drupal console provides config:import:single, but it can't be used in D9 due to a bug. It's also unclear whether drupal console will be properly maintained.

There are many use cases for importing single config files. This is really trivial to do through the GUI so it boggles my mind why this would be so hard to implement properly via drush.

meanderix avatar Sep 23 '21 12:09 meanderix

Just to add another voice here that I'm suddenly unable to create new configuration via Drush config-set when this was previously a useful part of my workflow for our sites:

drush @site-aliases.z7cup7pftbvyq.master config-set d8platform_events.settings event_date_format_date_only "D jS M Y" -y
>  [error]  Config d8platform_events.settings does not exist

In SiteProcess.php line 214:

  The command "ssh -o PasswordAuthentication=no [email protected] 'drush config-set d8platform_events.settings event_date_format_date_only '\''D jS M Y'\'' -y --uri=https://www.example.co.uk/ --root=/app/web'" failed.

  Exit Code: 1(General error)

  Working directory:

  Output:
  ================


  Error Output:
  ================
   [error]  Config d8platform_events.settings does not exist

This previously worked fine :-/

Bw

A

alexharriesredactive avatar Feb 22 '22 10:02 alexharriesredactive

drush config-set stage_file_proxy.settings has suddenly stopped working for me too, getting [error] Config stage_file_proxy.settings does not exist.

Edit: Discovered that this was due to a module not being properly uninstalled (it had a core.extension entry but the module files had been removed). After fixing this, config-set started working again.

aleksip avatar Mar 27 '22 17:03 aleksip

I have the same problem in Drush 11.4.

Removing of the validation resolves this issue as the set() function gives the option to create the setting when it doesn't exist.

brrrm avatar Jan 05 '23 12:01 brrrm

I am not sure if this is enough, but seems like it should be :)

donquixote avatar Jan 26 '23 22:01 donquixote

@donquixote Nice to see you around! Yo, that would be a super simple fix, which lookd reasonable.

geek-merlin avatar Jan 26 '23 23:01 geek-merlin

OK, lets do this in next major version

weitzman avatar Feb 21 '23 03:02 weitzman

Woooot! Thanks a lot for fixing this moshe.

geek-merlin avatar Mar 13 '23 15:03 geek-merlin

Just for note here. Since the --value option is removed in Drush 11, we need to replace the option with : cat $config_file | drush @alias cset $config_name --format=yaml ? - -y

ken-cit avatar Jun 16 '23 08:06 ken-cit