You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What problem would the enhancement address for VIP?
As explained at woocommerce/woocommerce#27696 there is a race condition when delete_option('foo') is followed by add_option('foo', '...').
Describe the solution you'd like
Having a sniff that looked for a delete_option() call followed by an add_option() immediately
or at some point within the same scope, for the same option key, could flag this race condition and suggest using update_option() instead.
Starting to work on this one roughly...
I believe that the add_option() call with the same option name would have to immediately follow the delete_option(). Being in the same function or method call may be too broad of a scope? (I'm not sure.)
E.g. the sniff would not flag this as a race condition:
function reset_settings() {
$defaults = get_default_settings();
delete_option( 'my_settings' );
// a whole bunch of other stuff is done here before the option gets added back
add_option( 'my_settings', $defaults );
}
Activity
rebeccahum commentedon Mar 11, 2021
Do you have any examples on what would be considered in scope?
GaryJones commentedon Mar 11, 2021
Within the same function or method call.
rebeccahum commentedon Mar 29, 2021
Starting to work on this one roughly...
I believe that the
add_option()call with the same option name would have to immediately follow thedelete_option(). Being in the same function or method call may be too broad of a scope? (I'm not sure.)E.g. the sniff would not flag this as a race condition:
Or this one:
GaryJones commentedon Apr 2, 2021
Can certainly start with looking at the calls being in consecutive statements.