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

Autoload max size #5671

Closed
wants to merge 125 commits into from
Closed

Autoload max size #5671

wants to merge 125 commits into from

Conversation

pbearne
Copy link

@pbearne pbearne commented Nov 14, 2023

But this has broken the tests
But that said the new result may be right as the sizz override the value passed in
Adjusted the formatting for better readability in the 'wpAutoloadValuesToAutoload.php' file. This enhancement applies to all test functions. Additionally, a commented-out filter has been removed from the 'option.php' file because it was not being used. This commit makes the code cleaner and improves the effectiveness of the tests.
src/wp-includes/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
tests/phpunit/tests/option/wpAutoloadValuesToAutoload.php Outdated Show resolved Hide resolved
tests/phpunit/tests/option/wpAutoloadValuesToAutoload.php Outdated Show resolved Hide resolved
tests/phpunit/tests/option/wpAutoloadValuesToAutoload.php Outdated Show resolved Hide resolved
src/wp-includes/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.

This looks great to me at this point. Thanks for all the iterations @pbearne!

Copy link
Member

@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.

I think this is looking great. Nice work @pbearne and @felixarntz. I've left a few comments, but nothing blocking. I think we can land this early and address new concerns as follow-up tasks.

Technically speaking, I do agree with @felixarntz's concern here, though I think it would be better to leave things as is for now, rather than creating the opportunity for unexpected values to be supported as "true" and wait for real bug reports to determine if we need to expand the checks in that switch statement.

src/wp-includes/option.php Outdated Show resolved Hide resolved
src/wp-includes/option.php Show resolved Hide resolved
src/wp-includes/option.php Show resolved Hide resolved
* @return string Returns the original $autoload value if explicit, or 'auto-on', 'auto-off',
* or 'auto' depending on default heuristics.
*/
function wp_determine_option_autoload_value( $option, $value, $serialized_value, $autoload ) {
Copy link
Member

Choose a reason for hiding this comment

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

Not a blocker, but I think the purpose of this function is not clear based on its name. I'd propose changing this to wp_normalize_option_autoload_value() instead. Happy to consider this in in a follow-up ticket if needed.

Copy link
Member

Choose a reason for hiding this comment

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

It's an @access private function anyway, so we could change the name later. Happy to reconsider in a follow up.

* @param string $option The passed option name.
* @param mixed $value The passed option value to be saved.
*/
$autoload = apply_filters( 'wp_default_autoload_value', null, $option, $value, $serialized_value );
Copy link
Member

Choose a reason for hiding this comment

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

At this point, we're assuming the autoload value is undetermined (i.e., null), but that's not necessarily the case. That's probably fine, since we're already normalized and returned all of the supported values above, but could lead to unforeseen bug reports. I don't think we need to adjust anything, but wanted to flag for consideration.

@joemcgill
Copy link
Member

@felixarntz I left feedback on your comment in my PR review. But since that doesn't show up in Trac, I'll summarize:

Technically speaking, I agree but I think it would be better to leave things as is for now, rather than creating the opportunity for unexpected values to be supported as "true" and wait for real bug reports to determine if we need to handle other values.

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.

Nit-pick

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

felixarntz commented Mar 22, 2024

@joemcgill Replying to your feedback:

Technically speaking, I do agree with @felixarntz's concern here, though I think it would be better to leave things as is for now, rather than creating the opportunity for unexpected values to be supported as "true" and wait for real bug reports to determine if we need to expand the checks in that switch statement.

I would generally agree with your assessment, but leaving this BC value handling out actually breaks previously existing unit tests. That to me is a reasonable indicator that we need to have this condition to convert technically unsupported values to true for BC. It doesn't really change whether or not this is a theoretical or practical concern, but we previously added tests ensuring those unsupported values evaluate as true, so I would feel uneasy about removing those tests.

LMKWYT.

@joemcgill
Copy link
Member

Ah, I had missed that there were previous tests breaking. In that case, I’d prioritize ensuring previous tests still pass, though it’s probably worth reviewing why the tests were written the way they were to see if they are unnecessarily broad

@felixarntz
Copy link
Member

@joemcgill Looking at the source of those tests, they are quite old, coming from https://core.trac.wordpress.org/ticket/31119 / https://core.trac.wordpress.org/changeset/31278.

Since at that time a boolean false ended up as 'yes', which certainly makes no sense, these tests were added which additionally assert that pretty much anything else does end up as 'yes'.

I don't feel strongly about the course of action here either way. I don't think there's realistically a great danger of changing those tests, because it's unlikely values like array() are passed to this function - why would someone do that? :) As always, I'm sure it happens but it's probably irrelevant talking at scale. More importantly, if we removed the BC handling, such an option would typically end up as auto, which would result in it still being autoloaded. So the only real "risk" from that change would be that the value is no longer considered explicit and thus could be overwritten by core at some point.

Concluding, I'd be okay removing the BC handling and adjusting the relevant tests to assert 'auto' instead of 'yes'. Let me know if you're still onboard with that given the additional context.

@joemcgill
Copy link
Member

@felixarntz I think I'm missing something. Looking at this PR, the test cases you're referencing don't seem to be changed (besides changing yes/no to on/off).

@felixarntz
Copy link
Member

@joemcgill That's my point. They aren't changed right now because the PR includes the extra BC handling. But if I remove that, they'll fail, so they'd need to be changed to expect 'auto' instead of 'on' ('yes' in legacy).

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 Below are the changes that would be needed to remove the BC handling.

src/wp-includes/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
@joemcgill
Copy link
Member

@felixarntz

That's my point. They aren't changed right now because the PR includes the extra BC handling.

That's what I missed 😄 — I thought you were asking whether we should add some BC handling to this PR, not whether we should remove the BC handling that was already put in place. Thanks for clarifying.

I actually think I prefer the changes you've suggested above to handle unsupported values as if they were null and have them processed using the default logic (which functionally will still cause them to be autoloaded, so it's not really a BC). It could also be helpful to add a doing_it_wrong() where you previously had the BC logic to encourage developers to update their code to supported values.

…provements.

Co-authored-by: Joe McGill <801097+joemcgill@users.noreply.github.com>
Co-authored-by: Mukesh Panchal <mukeshpanchal27@users.noreply.github.com>
Copy link
Member

@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.

The latest updates look good to me, @felixarntz.

@felixarntz felixarntz closed this Apr 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
7 participants