Skip to content

[Console] BUG: revert negatable ansi #41723

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
wants to merge 2 commits into from
Closed

Conversation

batenburg
Copy link

@batenburg batenburg commented Jun 16, 2021

Q A
Branch? 5.3
Bug fix? yes
New feature? no
Deprecations? no
Tickets N/A
License MIT
Doc PR N/A

When I create a command and configure it with the addOption 'no-ansi', the current 5.3 is throwing an exception.

The reason behind it is, that it is configure as negatable. When it is adding it check if the no-ansi is exists. Then it throws an exception.
In the 5.2 situation it then checked if the options equals. If not throw an exception.

https://github.com/symfony/console/blob/5.3/Input/InputDefinition.php#L255 part where the check is coming for the negatable and throws an exception.
https://github.com/symfony/console/blob/5.3/Input/InputDefinition.php#L233 The equals check where in the past the error was prevented.

Reverting the option to two values, seems like the right solution.

When I create a command and configure it with the addOption 'no-ansi', the current 5.3 is throwing an exception.

The reason behind it is, that it is configure as negatable. When it is adding it check if the no-ansi is exists. Then it throws an exception.
In the 5.2 situation it then checked if the options equals. If not throw an exception.

https://github.com/symfony/console/blob/5.3/Input/InputDefinition.php#L255 part where the check is coming for the negatable and throws an exception.
https://github.com/symfony/console/blob/5.3/Input/InputDefinition.php#L233 The equals check where in the past the error was prevented.

Reverting the option to two values, seems like the right solution.
@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 5.4 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

@carsonbot carsonbot added this to the 5.3 milestone Jun 16, 2021
@YaFou
Copy link
Contributor

YaFou commented Jun 16, 2021

I understand your issue but I think this is not the best solution to revert changes to the ansi option. In my opinion, you should apply the same check as here with the negatable options.
Please provide also a test for this issue.

@derrabus
Copy link
Member

derrabus commented Jun 16, 2021

I'd also prefer to not revert the change.

I understand that on Symfony 5.2, adding a --no-ansi option was kind-of a valid thing to do because the component did not specify it. Can we find a way to gracefully allow commands to do that and maybe trigger a deprecation in that case?

edit: I was wrong here, --no-ansi did exist on 5.2.

@carsonbot carsonbot changed the title BUG: revert negatable ansi [Console] BUG: revert negatable ansi Jun 16, 2021
@batenburg
Copy link
Author

@YaFou I had also checked to add the check (https://github.com/symfony/console/blob/5.3/Input/InputDefinition.php#L233), beacuse I add an option with the name no-ansi it is comparing with the name ansi and then the check will return false, That is not working,

Reproduce the bug. Create a command class, in the configure method set $this->addOption('no-ansi', null, InputOption::VALUE_NONE, 'Disable ANSI output'), you can also try it with the negatable, will be the same result.

@batenburg
Copy link
Author

@YaFou and @derrabus another solution which comes to my mind is removing the check if it exists on negatable. What do you think?

@stof
Copy link
Member

stof commented Jun 16, 2021

Well, creating the same option in a command and in the application is something we should forbid, as things will break in subtle ways if the 2 places don't apply the same config on the option.

@batenburg
Copy link
Author

@stof true point, that is why I would propose a revert, becasue then I can add someting twice with the same settings. which aint possible for a negetable

@stof
Copy link
Member

stof commented Jun 16, 2021

I agree with the revert in 5.3, but I think 5.4 should deprecated overriding application-level options (and 6.0 should forbid it), to avoid such subtle breakages.

@YaFou
Copy link
Contributor

YaFou commented Jun 16, 2021

Why not deprecate it now @stof? Maybe because it is on a maintenance branch?

@stof
Copy link
Member

stof commented Jun 16, 2021

Maybe because it is on a maintenance branch?

yes. Deprecations cannot be introduced in patch releases

@derrabus
Copy link
Member

I agree with the revert in 5.3, but I think 5.4 should deprecated overriding application-level options (and 6.0 should forbid it), to avoid such subtle breakages.

If we do this, I'd also like to switch back to negatable on 6.0.

Copy link
Member

@derrabus derrabus left a comment

Choose a reason for hiding this comment

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

The tests need some love after your change.

@jderusse
Copy link
Member

jderusse commented Jun 21, 2021

Before merging this PR in 5.3, could you please open a PR in 5.4 that deprecate overriding an option, and allow us to revert this PR in 6.0?

@GrahamCampbell
Copy link
Contributor

👍 for merging this. This issue is causing a lot of issues for Laravel users, which make up a large number of monthly downloads of this component.

@GrahamCampbell
Copy link
Contributor

Better to break code that's only been here for a few weeks, than to break code that's been here for years.

@jderusse
Copy link
Member

Hmm.. I dug into the issue and started working on a fix (#41792), but I realized that this does not make sense.

  1. In Symfony <5.3, You were not allowed to redefine an option UNLESS the options are exactly identical. The single change that is allowed is the description.
  2. The ansi and no-ansi are defined in the Command's definition, which means these are applied AFTER the user's command option (see
    $this->fullDefinition->setOptions($this->definition->getOptions());
    $this->fullDefinition->addOptions($this->application->getDefinition()->getOptions());
    ), which means they override the user's definition

Both previous points leads to: in symfony < 5.3, adding an option ansi or --no-ansi has no effect.

This issue is causing a lot of issues for Laravel users, which make up a large number of monthly downloads of this component.

Do you have such issue @GrahamCampbell ? because laravel/tinker#127 is not related.
in laravel/tinker#127 the issue is: previously both ansi and --no-ansi return false. While now no-ansi returns true.

This issue should be addressed by #41794

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.

8 participants