Custom Drush Commands Not Recognized After Upgrading to Drush 12.4.3

Created on 8 September 2024, 4 months ago
Updated 10 September 2024, 4 months ago

Problem/Motivation

I am currently using Drupal 10.6.1. After updating the Drupal core to version 10.2.2 and Drush from version 11.0 to 12.4.3, I am facing an issue with my custom module that contains Drush commands.

In this module, I use custom Drush commands. However, after updating to Drush 12.4.3, these commands no longer work. Every time I try to execute them, I get the following error:

[Symfony\Component\Console\Exception\NamespaceNotFoundException]
There are no commands defined in the "mc" namespace.

namespace Drupal\my_custom_module\Commands;

use Drupal\my_custom_module\MycustomCronTask;
use Drush\Commands\DrushCommands;

/**
 *
 */
class MyCustomModuleCommands extends DrushCommands {

  /**
   * @var \Drupal\my_custom_module\WebJobCronTask
   */
  protected $cronTask;


  /**
   * @param \Drupal\my_custom_module\MyCustomModuleCronTask $cronTask
   */
  public function __construct(MyCustomModuleCronTask $cronTask) {
    parent::__construct();
    $this->cronTask = $cronTask;
  }


  /**
   * Import or delete data from Api
   * @command mc:import
  * @param array $options
   * @usage drush mc:import
   * @usage drush mc:import 
   *
   */
  public function import(array $options = ['skip-hours' => FALSE]) {
    $this->cronTask->execute($options);
  }

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

🐛 Bug report
Status

Postponed: needs info

Version

10.2

Component
Other 

Last updated 23 minutes ago

Created by

🇹🇳Tunisia drupaldevGirl

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @drupaldevGirl
  • Status changed to Postponed: needs info 4 months ago
  • Drush is a separate project, which is supported at https://github.com/drush-ops/drush/issues. If you have determined this is a Drush problem then that is the place to report a bug.

  • 🇮🇳India sourav_paul Kolkata

    @cilefen I also faced the same issue on D10.1.8 with Drush 12.5.3, even no other custom Drush command is working.

    Here I'm sharing the output along with the drush command:

    1.
    I've created this command to update the node of account content type

    lando drush -v account:update-roles-based-subscription
     [info] Drush bootstrap phase: bootstrapDrupalRoot()
     [info] Change working directory to /app/docroot
     [info] Initialized Drupal 10.1.8 root directory at /app/docroot
     [info] Drush bootstrap phase: bootstrapDrupalSite()
     [info] Initialized Drupal site default at sites/default
     [info] Drush bootstrap phase: bootstrapDrupalConfiguration()
     [info] Drush bootstrap phase: bootstrapDrupalDatabase()
     [info] Successfully connected to the Drupal database.
     [info] Drush bootstrap phase: bootstrapDrupalFull()
    
    In Application.php line 657:
                                                                        
      [Symfony\Component\Console\Exception\NamespaceNotFoundException]  
      There are no commands defined in the "account" namespace.         
                                                                        
    
    Exception trace:
      at /app/vendor/symfony/console/Application.php:657
     Symfony\Component\Console\Application->findNamespace() at /app/vendor/symfony/console/Application.php:708
     Symfony\Component\Console\Application->find() at /app/vendor/drush/drush/src/Application.php:235
     Drush\Application->bootstrapAndFind() at /app/vendor/drush/drush/src/Application.php:191
     Drush\Application->find() at /app/vendor/symfony/console/Application.php:262
     Symfony\Component\Console\Application->doRun() at /app/vendor/symfony/console/Application.php:174
     Symfony\Component\Console\Application->run() at /app/vendor/drush/drush/src/Runtime/Runtime.php:110
     Drush\Runtime\Runtime->doRun() at /app/vendor/drush/drush/src/Runtime/Runtime.php:40
     Drush\Runtime\Runtime->run() at /app/vendor/drush/drush/drush.php:139
     require() at /app/vendor/drush/drush/drush:4
     include() at /app/vendor/bin/drush:119

    2.
    I've created this drush command to remove a role from user

    lando drush -v user:paid-money-role-removal
     [info] Drush bootstrap phase: bootstrapDrupalRoot()
     [info] Change working directory to /app/docroot
     [info] Initialized Drupal 10.1.8 root directory at /app/docroot
     [info] Drush bootstrap phase: bootstrapDrupalSite()
     [info] Initialized Drupal site default at sites/default
     [info] Drush bootstrap phase: bootstrapDrupalConfiguration()
     [info] Drush bootstrap phase: bootstrapDrupalDatabase()
     [info] Successfully connected to the Drupal database.
     [info] Drush bootstrap phase: bootstrapDrupalFull()
    
    In Application.php line 725:
                                                                      
      [Symfony\Component\Console\Exception\CommandNotFoundException]  
      Command "user:paid-money-role-removal" is not defined.          
                                                                      
      Did you mean one of these?                                      
          use                                                         
          user-add-role                                               
          user-block                                                  
          user-cancel                                                 
          user-create                                                 
          user-information                                            
          user-login                                                  
          user-password                                               
          user-remove-role                                            
          user-unblock                                                
          user:block                                                  
          user:cancel                                                 
          user:create                                                 
          user:information                                            
          user:login                                                  
          user:password                                               
          user:role:add                                               
          user:role:remove                                            
          user:unblock                                                
                                                                      
    
    Exception trace:
      at /app/vendor/symfony/console/Application.php:725
     Symfony\Component\Console\Application->find() at /app/vendor/drush/drush/src/Application.php:235
     Drush\Application->bootstrapAndFind() at /app/vendor/drush/drush/src/Application.php:191
     Drush\Application->find() at /app/vendor/symfony/console/Application.php:262
     Symfony\Component\Console\Application->doRun() at /app/vendor/symfony/console/Application.php:174
     Symfony\Component\Console\Application->run() at /app/vendor/drush/drush/src/Runtime/Runtime.php:110
     Drush\Runtime\Runtime->doRun() at /app/vendor/drush/drush/src/Runtime/Runtime.php:40
     Drush\Runtime\Runtime->run() at /app/vendor/drush/drush/drush.php:139
     require() at /app/vendor/drush/drush/drush:4
     include() at /app/vendor/bin/drush:119
  • As I mentioned in comment #2, Drush is not developed here.

  • 🇮🇳India sourav_paul Kolkata

    This issue was due to missing drush.services.yml file
    https://github.com/drush-ops/drush/issues/6116

  • Commands loaded with drush.services.yml will break in Drush 13. It is important to read the release notes and upgrade guides. As Drush is a separate project, I am closing this.

Production build 0.71.5 2024