Skip to content

[Console] Better required argument check in InputArgument #46264

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

Merged

Conversation

jnoordsij
Copy link
Contributor

Use better check for required arguments in InputArgument when setting default value,
to correctly account for combining multiple mode options

Q A
Branch? 4.4
Bug fix? yes
New feature? no
Deprecations? no
Tickets none
License MIT
Doc PR -

In the current implementation, when combining multiple argument modes, e.g. REQUIRED and IS_ARRAY, it is possible to also pass a default value, while this should raise an exception.

This fix uses the isRequired method (which does a bitwise comparison) instead of a full equality match, to always reject a default value if the argument is required.

Note: I am not sure if this is considered a bugfix or something that could be considered breaking backwards compatibility, as some configurations (e.g. combining the REQUIRED and IS_ARRAY modes and still passing a default value) that previously worked will break due to this.

@carsonbot
Copy link

Hey!

I see that this is your first PR. That is great! Welcome!

Symfony has a contribution guide which I suggest you to read.

In short:

  • Always add tests
  • Keep backward compatibility (see https://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (see https://symfony.com/releases)
  • Features and deprecations must be submitted against the 6.1 branch.

Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change.

When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

@chalasr
Copy link
Member

chalasr commented May 5, 2022

Works for me as a bugfix. Can you please add a test case that fails without your patch to prevent regressions?

@jnoordsij
Copy link
Contributor Author

Done! Also I got slightly confused by the allowed mode combinations on both InputArgument and InputOption, as for example combining the optional and required modes is currently allowed, but might lead to some unexpected/inconsistent behavior.

I'm willing to look into refactoring things and adding some additional validations, but this might be more of a problem with backwards compatibility, so maybe it is better to point such changes at 6.1?

@chalasr
Copy link
Member

chalasr commented May 5, 2022

Yes BC is especially important here, please do separate PRs/discussions for each bug-ish case. In the past, we have been merging bug fixes that turned into harmful BC breaks on this part of the code, which we had to revert.

@nicolas-grekas nicolas-grekas force-pushed the fix-input-argument-required-check branch from af9c97c to 89dd2bb Compare May 5, 2022 16:43
@nicolas-grekas
Copy link
Member

Thank you @jnoordsij.

@nicolas-grekas nicolas-grekas merged commit 4338337 into symfony:4.4 May 5, 2022
@jnoordsij jnoordsij deleted the fix-input-argument-required-check branch May 6, 2022 13:22
@fabpot fabpot mentioned this pull request May 14, 2022
This was referenced May 27, 2022
gilbertsoft added a commit to gilbertsoft/TYPO3-Console that referenced this pull request May 27, 2022
With the change symfony/symfony#46264 it's not
longer possible to provide a default value for required arguments and
the TYPO3 Console stops working with Symfony 6.0.9, 5.4.9 and 4.4.42.
gilbertsoft added a commit to gilbertsoft/TYPO3-Console that referenced this pull request May 27, 2022
With the change symfony/symfony#46264 it's not
longer possible to provide a default value for required arguments and
the TYPO3 Console stops working with Symfony 6.0.9, 5.4.9 and 4.4.42.
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.

4 participants