Skip to content
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

[Console] Fixes multiselect choice question defaults in non-interactive mode #27772

Merged
merged 1 commit into from Oct 12, 2018
Merged

[Console] Fixes multiselect choice question defaults in non-interactive mode #27772

merged 1 commit into from Oct 12, 2018

Conversation

veewee
Copy link
Contributor

@veewee veewee commented Jun 29, 2018

Q A
Branch? >4.1.1
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets
License MIT
Doc PR

This commit introduced a warning in multiselect mode:

PHP Notice:  Undefined index:  in /tmp/vendor/symfony/console/Helper/QuestionHelper.php on line 52
PHP Stack trace:
PHP   1. {main}() /tmp/vendor/phpro/grumphp/bin/grumphp:0
PHP   2. GrumPHP\Console\Application->run() /tmp/vendor/phpro/grumphp/bin/grumphp:31
PHP   3. GrumPHP\Console\Application->run() /tmp/vendor/phpro/grumphp/src/Console/Application.php:240
PHP   4. GrumPHP\Console\Application->doRun() /tmp/vendor/symfony/console/Application.php:145
PHP   5. GrumPHP\Console\Application->doRunCommand() /tmp/vendor/symfony/console/Application.php:262
PHP   6. GrumPHP\Console\Command\ConfigureCommand->run() /tmp/vendor/symfony/console/Application.php:904
PHP   7. GrumPHP\Console\Command\ConfigureCommand->execute() /tmp/vendor/symfony/console/Command/Command.php:251
PHP   8. GrumPHP\Console\Command\ConfigureCommand->buildConfiguration() /tmp/vendor/phpro/grumphp/src/Console/Command/ConfigureCommand.php:95
PHP   9. Symfony\Component\Console\Helper\QuestionHelper->ask() /tmp/vendor/phpro/grumphp/src/Console/Command/ConfigureCommand.php:156

Notice: Undefined index:  in /tmp/vendor/symfony/console/Helper/QuestionHelper.php on line 52

This PR fixes this issue by parsing the default value using the built-in validator if available. (which most likely is ...)

Copy link
Member

@chalasr chalasr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug fixes must be submitted against the lowest branch where they apply

For 2.8? :)


return $choices[$question->getDefault()];
return $question->getValidator() ? $question->getValidator()($default) : $default;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The validator wasn't applied here previously, this looks like a behavior change to me so cannot be part of the patch. Should be submitted as a new feature on master separately.

@chalasr chalasr modified the milestones: 4.1, 2.8 Jun 29, 2018
@veewee
Copy link
Contributor Author

veewee commented Jul 2, 2018

Hi @chalasr,

Thanks for the feedback!
I am not sure what you are expecting from me at this point. Do I need to create a patch for 2.8, another one for 4.1 (since the code has changed there) and a new feature request using the validator for master?

The way I see it:
2.8 until 4.1.1 worked "fine": it used the default value without any lookups in the choices.
From 4.1.1 on, the code selects an index from the choices list which breaks in non-interactive multiselect mode.

The only thing I did in this PR, is made the defaults parameter work in the same way it does in interactive mode. It is not really a behaviour change, but an inconsistency between operation modes which could be considered a bug.

Can you provide me some additional feedback? Thanks!

@chalasr
Copy link
Member

chalasr commented Jul 3, 2018

@veewee The updated code looks the same in 2.8 and 4.1 to me (the PR that introduced the bug is part of 2.8). Am I missing something that makes 2.8 free of this bug? Otherwise, this PR needs to be rebased on 2.8 being the lowest branch where the bug applies.

About making use of the validator in non-interactive mode, it potentially changes the return value of the method. Could be considered as a bugfix but anyways I think it should be discussed in a dedicated PR as it is not related to the bug fixed here.

@chalasr
Copy link
Member

chalasr commented Sep 8, 2018

ping @veewee :) should we close/take over?

@veewee
Copy link
Contributor Author

veewee commented Sep 28, 2018

Hi @chalasr,

Sorry for the delay.

To me, it is not very clear what the type of the 'default' parameter should be. For single options it makes sense to provide a key or name, but for multiple options it makes more sense to just provide the array of defaults instead of a comma separated string of indexes / names. Maybe the validator lookup is just overkill in this case... But that's up to you guys to decide.

Besides that, I also do not know which versions this affects and how it should be fixed in the different affected versions.

Since I have a lot of open questions about the subject, feel free to take this one over.

With kind regards.

@fabpot
Copy link
Member

fabpot commented Oct 10, 2018

@chalasr Can you take over this one?

@chalasr chalasr changed the base branch from 4.1 to 2.8 October 11, 2018 22:55
@chalasr chalasr changed the title [Console] Fixes multiselect choice question defaults in interactive mode [Console] Fixes multiselect choice question defaults in non-interactive mode Oct 12, 2018
@chalasr
Copy link
Member

chalasr commented Oct 12, 2018

@fabpot PR reworked, ready on my side.

foreach ($default as $k => $v) {
$v = trim($v);
$default[$k] = isset($choices[$v]) ? $choices[$v] : $v;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fabpot
Copy link
Member

fabpot commented Oct 12, 2018

Thank you @veewee.

@fabpot fabpot merged commit 099e265 into symfony:2.8 Oct 12, 2018
fabpot added a commit that referenced this pull request Oct 12, 2018
…n-interactive mode (veewee)

This PR was merged into the 2.8 branch.

Discussion
----------

[Console] Fixes multiselect choice question defaults in non-interactive mode

| Q             | A
| ------------- | ---
| Branch?       | >4.1.1
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

[This commit](41ffc69) introduced a warning in multiselect mode:

```
PHP Notice:  Undefined index:  in /tmp/vendor/symfony/console/Helper/QuestionHelper.php on line 52
PHP Stack trace:
PHP   1. {main}() /tmp/vendor/phpro/grumphp/bin/grumphp:0
PHP   2. GrumPHP\Console\Application->run() /tmp/vendor/phpro/grumphp/bin/grumphp:31
PHP   3. GrumPHP\Console\Application->run() /tmp/vendor/phpro/grumphp/src/Console/Application.php:240
PHP   4. GrumPHP\Console\Application->doRun() /tmp/vendor/symfony/console/Application.php:145
PHP   5. GrumPHP\Console\Application->doRunCommand() /tmp/vendor/symfony/console/Application.php:262
PHP   6. GrumPHP\Console\Command\ConfigureCommand->run() /tmp/vendor/symfony/console/Application.php:904
PHP   7. GrumPHP\Console\Command\ConfigureCommand->execute() /tmp/vendor/symfony/console/Command/Command.php:251
PHP   8. GrumPHP\Console\Command\ConfigureCommand->buildConfiguration() /tmp/vendor/phpro/grumphp/src/Console/Command/ConfigureCommand.php:95
PHP   9. Symfony\Component\Console\Helper\QuestionHelper->ask() /tmp/vendor/phpro/grumphp/src/Console/Command/ConfigureCommand.php:156

Notice: Undefined index:  in /tmp/vendor/symfony/console/Helper/QuestionHelper.php on line 52
```

This PR fixes this issue by parsing the default value using the built-in validator if available. (which most likely is ...)

Commits
-------

099e265 [Console] Fixes multiselect choice question in interactive mode with default values
This was referenced Nov 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants