Sometime in the last few weeks I noticed that drush dre no longer worked. Drush did not recognize dre as a valid command.

I upgraded to 8.x-3.0-beta1 yesterday.
I uninstalled devel.
I cleared the cache.
I installed devel again.
Drush shows devel as being installed.

9:21:16 › drush pml | grep -i devel
...
  Development                             Devel (devel)                                                               Enabled    8.x-3.0-beta1
...
9:22:48 › drush | grep -i devel
   runserver (rs, serve)                                 Runs PHP's built-in http server for development.
   views:dev (vd)                                        Set several Views settings to more developer-oriented values.

I have also run /core/rebuild.php a few times for unrelated reasons, and beyond that and drush cr, I don't know of any other ways to "discard" a bad setup. I would prefer not to reinstall everything!

Is there something else that I need to do, such as activate some sort of "development" flag in my Drupal installation, that would enable and activate devel Drush commands?'

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

arnaldop created an issue. See original summary.

moshe weitzman’s picture

There is no such flag ... Please run `drush cr`. I dont have more suggestions beyond that.

epapaniko’s picture

drush dre is an alias of drush devel:reinstall defined in Drupal\devel\Commands\DevelCommands. We have the same issue with all devel commands, we get:

$ drush devel:uuid

There are no commands defined in the "devel" namespace.

We've tested with Drupal core 8.8.1, Drush 9.7.1 and both Devel 8.x-3.x-dev and Devel 8.x-2.1.

It seems that the drush command service is not named properly, renaming it to devel.commands and clearing the cache fixes the issue for us in both 8.x-3.x-dev and 8.x-2.1. Attaching patch with the fix.

vinmassaro’s picture

Status: Active » Reviewed & tested by the community

Came to this issue because drush devel:uuid was not recognized as a command. Patch works, thanks!

moshe weitzman’s picture

Status: Reviewed & tested by the community » Fixed

Merged into 3.x and 2.x

jonathan1055’s picture

Status: Fixed » Needs work

Is it odd how that was not noticed before? The files were added in this commit in 2017 and not changed since then. So what has suddenly caused the commands not to be found?

Sorry for setting back to 'needs work' but I think there are two things we need to address:

  1. I noticed that if drush.services.yml needs the 's' on commands then so too should devel_generate/drush.services.yml ?
  2. I cannot recreate the original error with drush devel: after reverting back to the old incorrect devel.command: so I hesitate to provide a patch for develgenerate: when I can't prove that my change has any effect

It looks like something else is going on, which causes many users not to be affected by this change. I think we need to know what is actually happening, as we may be doing the wrong thing for other users by simply adding the 's' without knowing what causes the problem.

If I have got completely the wrong idea, please let me know.

epapaniko’s picture

@jonathan1055, Ι agree that any changes need to be reflected into devel_generate.

Two questions:

  1. Does the new service devel.commands work for you?
  2. What versions of Drupal core and Drush do you use when the old service devel.command works?
jonathan1055’s picture

Thanks @epapaniko

  1. Yes both the new devel.commands and old devel.command work. My drush.services.yml file is definitely being used because if I change services: to anything else I get 'The service file "modules/devel/drush.services.yml" is not valid' so I know I am using that file. But whether I have devel.commands, devel.command or devel.banana I can still use the drush commands
  2. I get the same results in Core 8.7, 8.8 and 8.9. In 8.7 and 8.8 drush --version gives
    Drush Launcher Version: 0.6.0
    Drush Commandline Tool 10.0.2
    

    and in 8.9 the version is 10.1.1

Maybe this is only a problem in Drush 9 and not 10? I don't have any immediate way to check that. Maybe someone else can?

For Devel Generate I have noticed another complication which slightly obsures the problem. In src/Commands/DevelCommands.php we have for example

   * @command devel:reinstall
   * @aliases dre,devel-reinstall

But in devel_generate/src/Commands/DevelGenerateCommands.php there is no : in the command name, we only have

   * @command devel-generate-users
   * @aliases genu

So the namespace "devel-generate:" is not going to be known anyway, and attempting drush devel-generate: will not produce anything. drush devel-generate (without the colon) does produces the commands but they are categorised in the -global group. This can be fixed separately.

So the question now is to test Drush 9 against Drush 10

moshe weitzman’s picture

I think its a convention for commands to be plural but it shouldn't matter. Both forms should work, for both drush9 and drush10. You should run `drush cr` when changing names and you are testing if things work.

Nothing more to do here?

arnaldop’s picture

Is it related that some of the commands show up under the devel heading, while others show up under the _global heading?

So the commands seemed not to be consistently working for everyone, and they are not being grouped together when running drush.

As was mentioned above, is this "programming by coincidence"? Is there something else going on that is causing this problem, and the proposed patch is only coincidentally working, or perhaps only working for a few people?

jonathan1055’s picture

@arnaldop

Is it related that some of the commands show up under the devel heading, while others show up under the _global heading?

That's what I mentioned in the second half of #10, this should be fixed but it is not related to the original problem.

@moshe weitzman

Nothing more to do here?

At minimum, as per #8.1 we should have devel_generate/drush.services.yml being consistent with drush.services.yml, whether we choose 'command' or 'commands'

I think its a convention for commands to be plural but it shouldn't matter. Both forms should work

Can you explain? Are you saying that anything will do here? If so, then how was the original problem discovered and why was the patch necessary?

@arnaldop, @epapaniko, @vinmassaro As you all experienced the problem with 'command' could you please run drush devel-generate (with no : at the end) on the exitsing -dev and tell us what you get. Do you see a list of the matching commands? Or do you get the "There are no commands defined in the {x} namespace" error?

If it turns out that we can't explain it, then I'll accept that, and we can just commit the change to use 'commands' in devel_generate/drush.services.yml to be on the safe side.

epapaniko’s picture

Running drush devel-generate and drush devel-generate-menus on the installation that I encountered the problem result in a

Command "x" is not defined.

However, I tested with a fresh install of the drupal-composer/drupal-project and the issue does not stand. Even with the old devel.command service, drush commands execute fine. So, it seems to be a drupal-project update to core 8.8.0+ problem. I've tried to pin-point the problematic dependency, but I haven't been able to do it; with everything I've done, I still get the error without the patch.

IMHO, since the patched service works on older unaffected installations and fresh installs and fixes the issue on upgraded ones, we should apply the fix on devel_generate and resolve this. The fact that devel_generate commands are not under the module's namespace is another issue.

jonathan1055’s picture

we should apply the fix on devel_generate and resolve this.

Yes I agree. Moshe said its a convention for commands to be plural which also matches with the drush9 example module and other contrib drush.services.yml files.

  • jonathan1055 committed 19f0bb3 on 8.x-3.x
    Issue #3106091 by epapaniko, jonathan1055, moshe weitzman, arnaldop:...

  • jonathan1055 committed ecd252a on 8.x-2.x
    Issue #3106091 by epapaniko, jonathan1055, moshe weitzman, arnaldop:...
jonathan1055’s picture

While we are on this subject, I think we might as well define the devel-generate commands to be under the sub-modules namespace. Then instead of the drush command list showing devel-generate commands being grouped under _global we will get:

 devel:                                                                                                                                                          
   devel:event (fne, fn-event, event)             List implementations of a given event and optionally edit one.                                                 
   devel:hook (fnh, fn-hook, hook)                List implementations of a given hook and optionally edit one.                                                  
   devel:reinstall (dre)                          Uninstall, and Install modules.                                                                                
   devel:services (devel-container-services, dcs) Get a list of available container services.                                                                    
   devel:token (token)                            List available tokens.                                                                                         
   devel:uuid (uuid)                              Generate a UUID.                                                                                               
 devel-generate:                                                                                                                                                 
   devel-generate:content (genc)                  Create content.                                                                                                
   devel-generate:media (genmd)                   Create media items.                                                                                            
   devel-generate:menus (genm)                    Create menus.                                                                                                  
   devel-generate:terms (gent)                    Create terms in specified vocabulary.                                                                          
   devel-generate:users (genu)                    Create users.                                                                                                  
   devel-generate:vocabs (genv)                   Create vocabularies.             

The original commands can be given as an alias so that any script or habit that devs are using will still work.

  • jonathan1055 committed 332db99 on 8.x-3.x
    Issue #3106091 by jonathan1055: Move devel-generate drush commands to be...

  • jonathan1055 committed a336514 on 8.x-2.x
    Issue #3106091 by jonathan1055: Move devel-generate drush commands to be...
jonathan1055’s picture

Status: Needs work » Fixed

Given that the original commit in #5 was for 3.x and 2.x I fixed the devel-generate commands and the namespace on both branches.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

merlin06’s picture

The problem here is drupal/token drush.services.yml defines a "devel.command" service. It should define a "token.command" service.
The drupal/token module is using the incorrect namespace.

Haha my boss has already found this and reported it to drupal/token here: https://www.drupal.org/project/token/issues/3145527

jonathan1055’s picture

Thanks @merlin06, so there was something unexplained, thanks for solving the mystery.

jonathan1055’s picture

Title: Missing Drush commands » Missing Drush commands - use devel.commands: