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

update_option() strict checks can cause false negatives #5139

Closed
wants to merge 23 commits into from

Conversation

mukeshpanchal27
Copy link
Member

In this PR i have updated 9 year old patch 22192.5.diff.

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
Contributor

@costdev costdev left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @mukeshpanchal27! I've left some test-related tidy-up comments in this review. 🙂

tests/phpunit/tests/option/option.php Outdated Show resolved Hide resolved
tests/phpunit/tests/option/option.php Outdated Show resolved Hide resolved
tests/phpunit/tests/option/option.php Outdated Show resolved Hide resolved
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.

@mukeshpanchal27 Looks good for the most part, one point of feedback.

src/wp-includes/option.php Outdated Show resolved Hide resolved
src/wp-includes/option.php Outdated Show resolved Hide resolved
@mukeshpanchal27
Copy link
Member Author

Thanks @costdev and @felixarntz for the initial feedback. The PR is once again ready for review.

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.

@mukeshpanchal27 This looks solid now, the only thing that would be great to add is a reusable function for the duplicate code per @spacedmonkey's feedback.

Also see #5139 (comment), and then it would be great to add a single unit test for it with a data provider to check different values and their comparisons.

@mukeshpanchal27
Copy link
Member Author

@costdev raised some backward compatibility (BC) issues that we coordinated and resolved. If there are any remaining issues, please share them so that we can address them promptly. It is essential to land this as soon as possible to allow sufficient time for testing.

@felixarntz
Copy link
Member

@mukeshpanchal27 I just committed the side PR #5250 in https://core.trac.wordpress.org/changeset/56648.

Can you please refresh this branch against trunk to fix the merge conflict? Then we can reassess what the current behavior and tests look like.

@mukeshpanchal27
Copy link
Member Author

@felixarntz @costdev @spacedmonkey and @joemcgill Looks like we have some failures now that the tests have been committed to trunk.

tests/phpunit/tests/option/option.php Outdated Show resolved Hide resolved
* @param mixed $old_value One of the values to compare.
* @param mixed $new_value The other value to compare.
*/
public function test_update_option_should_hit_cache_when_loosely_equal_to_existing_value_and_cached_values_are_faithful_to_original_type( $old_value, $new_value ) {
Copy link
Member

Choose a reason for hiding this comment

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

Now that a set of tests confirming current behavior are in trunk, via https://core.trac.wordpress.org/changeset/56648, is this test still needed?

tests/phpunit/tests/option/option.php Outdated Show resolved Hide resolved
@joemcgill
Copy link
Member

@mukeshpanchal27 I think test failures are to be expected since the code in this PR will change the current behavior. Can you review the failing tests and confirm whether they are failing because of an intended change in behavior (meaning we need to update the tests) or because the current code is introducing a regression (meaning we need to adjust the functionality)?

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.

Now that the other tests were committed, there are two duplicate tests here that only have additional assertions but cover the same situations.

tests/phpunit/tests/option/option.php Outdated Show resolved Hide resolved
tests/phpunit/tests/option/option.php Outdated Show resolved Hide resolved
@felixarntz
Copy link
Member

@mukeshpanchal27 I see you already updated the PR before I posted my feedback 😆

That's great, just one additional consideration would be to maybe add the assertions for the number of DB queries to the existing tests? Those were not covered in the existing tests, so if we want to ensure that remains the same, it's a good idea to add it. We shouldn't change anything else in those existing tests.

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.

Looking at the test failures in https://github.com/WordPress/wordpress-develop/actions/runs/6264701987/job/17011971702?pr=5139, I think there is a problem with the logic here because it incorrectly forces values into certain results that is not the same as how they will be interpreted in the DB.

Reviewing a few test failures as examples:

src/wp-includes/option.php Outdated Show resolved Hide resolved
Copy link
Contributor

@costdev costdev left a comment

Choose a reason for hiding this comment

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

Thanks for the updates @mukeshpanchal27! Awesome job everyone on protecting BC here!

Just some final docs feedback in this review.

tests/phpunit/tests/option/isEqualDatabaseValue.php Outdated Show resolved Hide resolved
tests/phpunit/tests/option/option.php Outdated Show resolved Hide resolved
tests/phpunit/tests/option/option.php Outdated Show resolved Hide resolved
src/wp-includes/option.php Outdated Show resolved Hide resolved
tests/phpunit/tests/option/isEqualDatabaseValue.php Outdated Show resolved Hide resolved
tests/phpunit/tests/option/isEqualDatabaseValue.php Outdated Show resolved Hide resolved
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.

@mukeshpanchal27 Thank you for the updates, this is looking great now. Marking as approved already.

It would be great if you could incorporate my previous feedback from #5139 (comment) (add assertions for the number of queries to the tests from https://core.trac.wordpress.org/changeset/56648), to ensure in the correct number of database requests is sent. This is especially beneficial for the test cases where the option should not be updated, because only asserting the result of false may also come from another part of the logic within the function.

Co-authored-by: Colin Stewart <79332690+costdev@users.noreply.github.com>
@mukeshpanchal27
Copy link
Member Author

@felixarntz I try to check query on trunk but there is some inconsistency because of false-y test. Please check side PR #5272

@felixarntz
Copy link
Member

Thanks @mukeshpanchal27, I have left feedback on #5272 (review).

@felixarntz
Copy link
Member

@costdev In the interest of getting this committed before Beta 1 and not blocking based on #5272, would you be okay approving this as is, and keeping the ticket open for the follow up test coverage for the number of queries added?

I think other than not blocking this commit, it would also strike a great balance related to our comment exchange on #5272, where as part of the production logic change here, we wouldn't modify the tests much, ensuring things still pass as they were before.

@costdev
Copy link
Contributor

costdev commented Sep 25, 2023

@felixarntz If you're confident that the query-related test failures don't include a BC break, I'm okay with this being committed, then query-related test coverage being added afterwards (which should include investigation to confirm no BC breaks).

@felixarntz
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants