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

Options: Remove pre-filter juggling #5498

Closed

Conversation

joemcgill
Copy link
Member

This removes the logic that disables pre-filteres when deciding whether to updating options and network options

See: 22192, 59360.

Trac ticket: https://core.trac.wordpress.org/ticket/22192


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

Copy link
Member Author

@joemcgill joemcgill left a comment

Choose a reason for hiding this comment

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

Leaving some notes for myself to follow-up on

Comment on lines +722 to +723
add_filter( 'pre_option_foo', '__return_false' );
add_filter( 'pre_site_option_foo', '__return_false' );
Copy link
Member Author

Choose a reason for hiding this comment

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

Should these use the pattern used in other tests here?

$hook_name = is_multisite() ? 'pre_site_option_foo' : 'pre_option_foo';

Copy link
Member

Choose a reason for hiding this comment

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

I don't feel strongly about this, but I think having both filters potentially helps uncover future weirdness in behavior more reliably than only having one of them set.

Alternatively, we duplicate this test and have both versions covered (one test with both filters, the other with only the one appropriate filter).

Comment on lines +725 to +729
/*
* When the network option is equal to the filtered version, update option will bail early.
* Otherwise, The pre-filter will make the old option `false`, which is equal to the
* default value. This causes an add_network_option() to be triggered.
*/
Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure this comment is accurate, as this was copy/pasta from the update_option tests.

Comment on lines 814 to 815
* This should succeed, since the 'foo' option does not exist in the database.
* The default value is false, so it differs from 0.
Copy link
Member Author

Choose a reason for hiding this comment

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

Update inline comment

Comment on lines 837 to 838
* This should succeed, since the 'foo' option has a value of 1 in the database.
* Therefore it differs from 0 and should be updated.
Copy link
Member Author

Choose a reason for hiding this comment

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

Update inline comment

* If the option will result in the same DB value, the option should not
* be updated. Otherwise, the option should be updated regardless of the prefilter.
*/
if ( _is_equal_database_value( $option, true ) ) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure if it's ok to use the helper function here, or if that makes the tests susceptible to side effects from changes to that business logic. Could also explicitly list the values we expect to be equal in an array and run in_array() on the $option value.

Copy link
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

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

@joemcgill This looks solid so far, though we should triple check we don't reintroduce the same bug with the gmt_offset option that the pre filter juggling originally fixed here. Or have we come to the conclusion that this bug somehow is invalid / wontfix? Let's clarify that before proceeding.

Comment on lines +722 to +723
add_filter( 'pre_option_foo', '__return_false' );
add_filter( 'pre_site_option_foo', '__return_false' );
Copy link
Member

Choose a reason for hiding this comment

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

I don't feel strongly about this, but I think having both filters potentially helps uncover future weirdness in behavior more reliably than only having one of them set.

Alternatively, we duplicate this test and have both versions covered (one test with both filters, the other with only the one appropriate filter).

*/
$this->assertTrue( update_option( 'foo', 0 ) );
// This will fail since it has been pre-filtered to the same value.
$this->assertFalse( update_option( 'foo', 0 ) );
}
Copy link
Member

Choose a reason for hiding this comment

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

It makes sense that these tests are being updated given the change here, however we need to make sure we don't introduce the problem flagged in https://core.trac.wordpress.org/ticket/22192#comment:52 again, which originally led to introducing the pre filter juggling we are reverting here (see fix in https://core.trac.wordpress.org/changeset/56717).

How does this revert address that bug? I am not against this, but I am wary of us making a change to clean up this code while potentially reintroducing the problem. How can we verify that that's not the case? Have you tested this?

Copy link
Member

@felixarntz felixarntz Oct 16, 2023

Choose a reason for hiding this comment

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

Per @mukeshpanchal27's comment in #5498 (review), looks like that bug is indeed reintroduced. So we either need to find an alternative solution or settle on this BC break being okay.

While the latter may sound controversial, maybe it would be okay, something to cover in a dev note and encourage changing, as it is certainly an edge case.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think we need a test specifically for that bug, and not one that abstracts the bug to a root cause check, like this one does. I would not be surprised if removing the pre-filtering, reintroduces the bug, which my require additional consideration.

Copy link
Member

@mukeshpanchal27 mukeshpanchal27 left a comment

Choose a reason for hiding this comment

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

This changes again introduce gmt_offset error: WordPress/gutenberg#54806 (comment)

Screenshot 2023-10-16 at 8 35 44 PM

)
) {
return false;
}

if ( $default_value === $raw_old_value ) {
if ( $default_value === $old_value ) {
Copy link
Member

Choose a reason for hiding this comment

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

Couldn't verify but this will introduce error in Yoast. Per https://core.trac.wordpress.org/ticket/59360#comment:35

@joemcgill
Copy link
Member Author

Closing this now that we've chosen to revert the changes from the 6.4 release cycle.

@joemcgill joemcgill closed this Oct 16, 2023
@joemcgill joemcgill deleted the update/22192-remove-prefilter-logic branch October 11, 2024 19:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants