Problem/Motivation

Disclaimer: This was found and fixed by an LLM. It also helped write this issue summary.

ConsoleCompilerPass::process() uses Definition::setTags() to register auto-discovered #[AsCommand] services:

$definition
  ->setAutowired(TRUE)
  ->setPublic(TRUE)
  ->setTags(['console.command' => []]);

setTags(['console.command' => []]) stores the tag as an empty array of instances ([]). Definition::addTag('console.command') stores it correctly as [[]] - an array containing one instance.

In symfony/console 8.0.x, AddConsoleCommandPass::process() iterates per-service and reads command names directly from the #[AsCommand]attribute. An empty tag instance list is harmless - the command is still registered.

In symfony/console 8.1, AddConsoleCommandPass::process() was refactored to iterate per-tag-instance:

foreach ($container->findTaggedServiceIds('console.command', true) as $id => $tags) {
    foreach ($tags as $tag) {   // $tags is [] — inner loop never runs
        $commandServices[$id]...
    }
}

With setTags(['console.command' => []]), $tags is [], the inner loop never executes, and the service is silently dropped from the command map. Auto-discovered #[AsCommand] commands are absent from vendor/bin/dr list with no error or warning.

Steps to reproduce

Proposed resolution

- ->setTags(['console.command' => []]);
+ ->addTag('console.command');

addTag() is compatible with both 8.0.x and 8.1.x.

Remaining tasks

See if this is still needed after #3606744: Invokable commands dont show their usages in help and #3588847: Update to Symfony 8.1

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Issue fork drupal-3607060

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

mstrelan created an issue. See original summary.

mstrelan’s picture

Issue summary: View changes
mstrelan’s picture

Status: Active » Needs review

Run #1 with Symfony 8.1: https://git.drupalcode.org/project/drupal/-/pipelines/869562
This has 47 test failures. Cspell also fails due to the generated composer.json, opened #3607061: Don't spellcheck composer.json

Run #2 with Symfony 8.1 and the fix: https://git.drupalcode.org/project/drupal/-/pipelines/869568/
No test failures, lots of deprecations. Not in scope here.

Run #3 with just the fix: https://git.drupalcode.org/project/drupal/-/pipelines/869575
All green

moshe weitzman’s picture

I'm not sure if this is a dupe of the recently submitted #3606744: Invokable commands dont show their usages in help

mstrelan’s picture

I don't know either, but the diff here is much smaller. I guess that issue should be tested against symfony/console 8.1.

smustgrave’s picture

@moshe and @mstrelan based on the comments should this be closed a duplicate and credit moved over to #3606744: Invokable commands dont show their usages in help ?

mstrelan’s picture

That other issue needs to be verified against symfony 8.1. If tests pass then we don't need this.

moshe weitzman’s picture

That testing will happen naturally in #3588847: Update to Symfony 8.1. So you can close this IMO.

smustgrave’s picture

Not comfortable making that call so will let @mstrealn do it. Am saving credit for the work done here.

mstrelan’s picture

My problem is if I use https://github.com/amateescu/ddev-drupal-dev and run ddev composer update I get symfony/console:8.1 and things are broken now.

mstrelan’s picture

Issue summary: View changes
Status: Needs review » Postponed

OK I read the docs and have set "pin-core-lock": true so now I don't get console 8.1. Marking as postponed just in case and updated remaining tasks with the two relevant tickets.

longwave’s picture

This change was needed over in #3588847: Update to Symfony 8.1, I merged in this MR and credited @mstrelan for the fix. This can probably be closed now?

moshe weitzman’s picture

Status: Postponed » Closed (duplicate)

Yes.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.