Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 #5139update_option()
strict checks can cause false negatives #5139Changes from 6 commits
0d02f09
00a66a7
e02ac1c
194cdf6
6497e62
e5a5eac
1f48d90
233c605
900bf38
b40f757
9f7b4f7
bf1ef31
ccf6435
1c9ef85
ea8adb3
5e233ff
a924b31
85840cc
9adbccf
2425818
c4159c3
48e5bcb
7e8a64f
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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 test appears to have been included in an earlier patch on the ticket. Despite its name, I'm still not sure what this test is actually testing.
update_option()
is a "setter" function, so the number of queries should change as the database is updated. This test reads more like it's testing a "getter" function, where the number of queries should be reduced when a value exists in the cache.Aside from that, why are we testing that the cache is hit? What do we expect to happen to the cache?
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.
I think this test as written is trying to confirm behavior which I think is wrong. From what I can tell, this is essentially ensuring that if an option is set and then updated to a value that is loosely equal, but not strictly equal (e.g.,
true
and1
), then the option will not be updated. However, I think that's wrong because there are valid reasons why you may want to update an option value from one type to another.Instead, what I think this ticket is trying to ensure, is that if you try to update an option with the same value that is strictly equal, then a database query will not be run because
update_option
will find that the value already exists in cache, whereas now, the cached value is not strictly equal for some reason.Maybe I'm misunderstanding?
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.
I run
test_update_option_should_hit_cache_when_loosely_equal_to_existing_value_and_cached_values_are_faithful_to_original_type
unit test for old and new/updatedupdate_option
function with dataset. Here is the observation.For all this dataset value it hit DB query in old
update_option
and it will not run any additional query in updated function.For all this dataset values it update the option in old
update_option
function but not in updated function.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.
That's right yeah, though the ticket also says:
So that's where the
if loosely equal, don't update
comes from.This also occurred to me when looking at the ticket and PR, and I had the same opinion as you but I didn't have any example use cases in mind.
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.
Spending some more time with this issue and it does seem like I misunderstood the details of what the current behavior is and what we are trying to achieve here. I've created an example PR that includes the basic unit tests from this PR along with a complete set of truthy and falsey use cases. You can see that there are 30 use cases where the tests fail (i.e, updates are happening when we don't expect them)—all of which are currently falsey use cases. So it seems to me that the original issue as reported might already be mostly fixed.
Also, (except for some falsey use cases) the current behavior already shows that you are not able to update the value of an option to a loosely equivalent scalar value of a different type (e.g., from
'1'
totrue
), So the goal here seems to be to further reduce the times where falsey values are being compared but result in a DB update when values are loosely equivalent.If there are falsey use cases that MUST keep the current behavior, then we should also add a unit test to ensure those are not effected by this, or future changes.
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 it would be helpful, I think it would be fine to add a passing version of these tests into trunk prior to any changes here. That said, I think it would be ok to do it all as a part of this ticket. What is not super clear to me from what I'm observing from the tests in my PR is whether any of the use cases that are currently failing can actually be fixed without introducing backwards compatibility breaks.
Ideally, we should have a complete set of use cases that all pass with the expected behavior of not doing a DB update when the new value is loosely equal to the existing value. For any cases where we MUST do DB updates even on loosely equivalent values, we should also have tests that confirm that behavior with some inline docs explaining why these can't be changed.
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.
@joemcgill I think either way works, but committing these tests standalone to
trunk
would clarify (also to future reviewers of this PR) that those changes continue to pass. Adding them here does not make it clear whether those tests would have also passed prior, i.e. whether they cover new or existing behavior.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.
Let me update the other PR so that it confirms only current behavior and I'll link it to that ticket so we can decide to commit it or not.
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.
+1
Also that by having tests already in
trunk
, if any of the tests are intended to change, those changes will be clear to see in this PR and changeset diff when this PR is committed. That means if there are any BC breaks we didn't catch during review, finding the problem doesn't mean to looking at every dataset, but only the changed ones.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.
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?