8000 [Console] Lazy commands are loaded, although they were not actually called · Issue #35479 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Console] Lazy commands are loaded, although they were not actually called #35479

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

Closed
lutzpetzoldt opened this issue Jan 27, 2020 · 1 comment
Closed

Comments

@lutzpetzoldt
Copy link
lutzpetzoldt commented Jan 27, 2020

Symfony version(s) affected: 4.3.10

Description
After updating from 4.3.9 to 4.3.10 the changes from #35094 lead to loading of lazy commands although they are not actually called. This occurs with commands where the first part of the name matches. For example if you have two lazy commands app:foo and app:foo:bar, and call bin/console app:foo, then app:foo:bar will also be instantiated. This should not happen according to the documentation (link). I think the problem is line 668 in Symfony\Component\Console\Application.php where the command always get instantiated even if it is a lazy command.

How to reproduce

  1. Create two lazy commands where the first part of the name matches, i.e. app:foo and app:foo:bar:
# App/Command/FooCommand.php
class FooCommand extends Command
{
    protected static $defaultName = 'app:foo';

    public function __construct(string $name = null)
    {
        var_dump('app:foo');
        parent::__construct($name);
    }
}

# App/Command/FooBarCommand.php
class FooBarCommand extends Command
{
    protected static $defaultName = 'app:foo:bar';

    public function __construct(string $name = null)
    {
        var_dump('app:foo:bar');
        parent::__construct($name);
    }
}
  1. Call bin/console app:foo. The console output shows that FooBarCommand get also instantiated.

Possible Solution
I think the problem is line 668 in Symfony\Component\Console\Application.php where the command always get instantiated just to get its name even if it is a lazy command.

Additional context

root@327000b4b57a:/var/www/portal# bin/console app:foo
/var/www/portal/src/Command/FooBarCommand.php:13:
string(11) "app:foo:bar"
/var/www/portal/src/Command/FooCommand.php:13:
string(7) "app:foo"
...
@chalasr
Copy link
Member
chalasr commented Jan 28, 2020

I'm looking at it.

@fabpot fabpot closed this as completed Feb 13, 2020
fabpot added a commit that referenced this issue Feb 13, 2020
…match (chalasr)

This PR was merged into the 3.4 branch.

Discussion
----------

[Console] Don't load same-namespace alternatives on exact match

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #35479
| License       | MIT
| Doc PR        | -
<!--
Replace this notice by a short README for your feature/bugfix. This will help people
understand your PR and can be used as a start for the documentation.

Additionally (see https://symfony.com/roadmap):
 - Always add tests and ensure they pass.
 - Never break backward compatibility (see https://symfony.com/bc).
 - Bug fixes must be submitted against the lowest maintained branch where they apply
   (lowest branches are regularly merged to upper ones so they get the fixes too.)
 - Features and deprecations must be submitted against branch master.
-->

Commits
-------

707c5ba [Console] Don't load same-namespace alternatives on exact match found
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants
0