-
-
Notifications
You must be signed in to change notification settings - Fork 388
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
Handle absence of value for --all-or-nothing
properly
#1296
Conversation
Hi @greg0ire I will try to add a failing test case if possible. I'll keep you posted. |
@greg0ire I added an extra permutation for the data provider of the What would you advice as next step? |
|
@greg0ire unfortunately your suggestion alone does not seem to do the trick. I've checked the hasOption method in Symfony and it seems that method is not a reliable way to know if a user passed the command option or not. In any case, I'll do a small refactor there to stop using |
Indeed! I think by using a default value different than |
I'm not sure @greg0ire I'll give it some thought over the week, since it seems like relying on the default value of the option may not work, as it can override the Doctrine project configuration. |
I guess if you set the default to |
That sounds like a good idea. |
--all-or-nothing
on config absence--all-or-nothing
properly
You can use |
@greg0ire how do you want to proceed regarding the PHPStan failures? THey seem to be originating from deprecations, and the BC check error I never seen it before. |
lib/Doctrine/Migrations/Tools/Console/ConsoleInputMigratorConfigurationFactory.php
Outdated
Show resolved
Hide resolved
Nice commit messages. I've seen the test failing, so you can squash both commits now, so that all commits pass the build. |
Don't worry about those, I'll take care of it. Regarding the BC-check, it seems to have been broken for a while: Nyholm/roave-bc-check-docker#32 |
e729e54
to
10b6936
Compare
return null; | ||
} | ||
|
||
return (bool) ($allOrNothingOption ?? true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the command does not have the option, the value will default to true
, but I guess it does not matter since all-or-nothing
is not used when the option is not defined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a problem, the default value of MigrationConfiguration
property allOrNothing
is false
, these changes always set the value to true if the option isn't passed at all AND the command doesn't have an all-or-nothing
option, for example ExecuteCommand
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean the option is used although it's not defined in the command? Where?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The option itself isn't used, but ConsoleInputMigratorConfigurationFactory->getMigratorConfiguration() is being called in ExecuteCommand->execute()
which in turn creates a MigratorConfiguration
with allOrNothing
set to true
because ExecuteCommand
doesn't have an all-or-nothing
option which results in the value not defaulting to notprovided
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically this method should look like this:
if (!$input->hasOption('all-or-nothing')) {
return null;
}
$allOrNothingOption = $input->getOption('all-or-nothing');
if ($allOrNothingOption === 'notprovided') {
return null;
}
return (bool) ($allOrNothingOption ?? true);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created a PR with the fix: #1308
This test case addition simulates what happens when the `--all-or-nothing` option is indicated, but no explicit value is passed. We'll set a default option, which is retrieved in case the option has not been provided, allowing us to override the value in case the option is different than the default value.
Thanks @agustingomes ! |
@agustingomes if you want to work on this, you can open a PR on 3.6.x to deprecate passing a value :) Here is an example: migrations/lib/Doctrine/Migrations/Tools/TransactionHelper.php Lines 22 to 32 in 01f89a1
|
@greg0ire I'll look into it the next days 👍🏼 |
During the iteration of the PR doctrine#1296 an idea to deprecate passing values to this option was suggested, given how complicated was to handle using that option without any value, which led to a bug and inconsistency with the documentation. As specified in the deprecation message, using this option from 4.0.x onwards in the CLI will be treated as `true`, and the option itself won't accept values.
During the iteration of the PR doctrine#1296 an idea to deprecate passing values to this option was suggested, given how complicated was to handle using that option without any value, which led to a bug and inconsistency with the documentation. As specified in the deprecation message, using this option from 4.0.x onwards in the CLI will be treated as `true`, and the option itself won't accept values.
This fixes a bug that was introduced in doctrine#1296 where the configuration value of allOrNothing got set to true if the command didn't have an all-or-nothing option. Now the value is set from input options only if the command that is being executed has an `all-or-nothing` option.
During the iteration of the PR doctrine#1296 an idea to deprecate passing values to this option was suggested, given how complicated was to handle using that option without any value, which led to a bug and inconsistency with the documentation. As specified in the deprecation message, using this option from 4.0.x onwards in the CLI will be treated as `true`, and the option itself won't accept values.
During the iteration of the PR doctrine#1296 an idea to deprecate passing values to this option was suggested, given how complicated was to handle using that option without any value, which led to a bug and inconsistency with the documentation. As specified in the deprecation message, using this option from 4.0.x onwards in the CLI will be treated as `true`, and the option itself won't accept values.
Expected behavior:
Upon specification of the option
--all-or-nothing
wraps multiple migrations into a transactionObserved behavior
Specifying
--all-or-nothing
by itself does not cause the desired effect, as the result of the statement$input->getOption('all-or-nothing')
isnull
, and therefore, in the absence of config, this value is ultimately evaluated tofalse
, therefore not wrapping multiple migrations into a single transaction.Summary