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

Do not override pagination args if woocommerce_hpos_pre_query doesn't override query #40551

Merged
merged 2 commits into from Oct 3, 2023

Conversation

jorgeatorres
Copy link
Member

@jorgeatorres jorgeatorres commented Oct 2, 2023

Submission Review Guidelines:

Changes proposed in this Pull Request:

In #39945 we introduced a filter (woocommerce_hpos_pre_query) that allows overriding of HPOS queries, but it currently sets internal pagination variables to NULL even when not actually being used:

list( $this->orders, $this->found_orders, $this->max_num_pages ) = apply_filters( 'woocommerce_hpos_pre_query', null, $this, $this->sql );

This is incorrect as those variables have default values (of 0) which should be preserved unless the query is, in fact, overridden.

Closes #40548.

How to test the changes in this Pull Request:

Using the WooCommerce Testing Instructions Guide, include your detailed testing instructions:

  1. Start with HPOS enabled in WC > Settings > Advanced > Features.
  2. Run the following snippet using WP-CLI (either wp run-eval or wp shell):
    wc_get_orders(
        [
     	   'status'   => 'all',
     	   'type'     => 'shop_order',
     	   'post__in' => [0],
     	   'limit'    => 1,
     	   'return'   => 'ids',
     	   'paginate' => true,
        ]
    );
  3. Confirm that the output is as follows:
    stdClass Object(
       [orders] => Array()
       [total] => 0
       [max_num_pages] => 0
    )
    
    In particular, total and max_num_pages should be 0.
  4. Go back to WC > Settings > Advanced > Features and disable HPOS.
  5. Repeat step 2 and confirm that the output is again that of step 3.

Changelog entry

  • Automatically create a changelog entry from the details below.

Significance

  • Patch
  • Minor
  • Major

Type

  • Fix - Fixes an existing bug
  • Add - Adds functionality
  • Update - Update existing functionality
  • Dev - Development related task
  • Tweak - A minor adjustment to the codebase
  • Performance - Address performance issues
  • Enhancement - Improvement to existing functionality

Message

Comment

@jorgeatorres jorgeatorres added the focus: custom order tables / HPOS Issues related to High-Performance Order Storage (HPOS) née Custom Order Tables. label Oct 2, 2023
@jorgeatorres jorgeatorres requested review from a team and barryhughes and removed request for a team October 2, 2023 17:37
@github-actions github-actions bot added the plugin: woocommerce Issues related to the WooCommerce Core plugin. label Oct 2, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Oct 2, 2023

Hi @barryhughes,

Apart from reviewing the code changes, please make sure to review the testing instructions as well.

You can follow this guide to find out what good testing instructions should look like:
https://github.com/woocommerce/woocommerce/wiki/Writing-high-quality-testing-instructions

@github-actions
Copy link
Contributor

github-actions bot commented Oct 2, 2023

Test Results Summary

Commit SHA: 17f81d1

Test 🧪Passed ✅Failed 🚨Broken 🚧Skipped ⏭️Unknown ❔Total 📊Duration ⏱️
API Tests25900202611m 0s
E2E Tests212007021924m 8s

To view the full API test report, click here.
To view the full E2E test report, click here.
To view all test reports, visit the WooCommerce Test Reports Dashboard.

@@ -351,16 +351,22 @@ public function test_pre_query_escape_hook_pass_limit() {
* @testdox A regular query will still work even if the pre-query escape hook returns null for the whole 3-tuple.
*/
public function test_pre_query_escape_hook_return_null() {
add_filter( 'woocommerce_hpos_pre_query', '__return_null', 10, 3 );
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 think it really matters, but we could simplify this to:

Suggested change
add_filter( 'woocommerce_hpos_pre_query', '__return_null', 10, 3 );
add_filter( 'woocommerce_hpos_pre_query', '__return_null' );

Copy link
Member

@barryhughes barryhughes left a comment

Choose a reason for hiding this comment

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

Looks good!

  • Straightforward change, tests well locally when invoking it via wp eval.
  • Confirmed the order list table is not impacted by this change (the filter and the condition following it are invoked when accessing this screen) and that pagination continues to work as expected.
  • I don't think there is a need for further analysis in this case, so will merge directly.

@barryhughes barryhughes merged commit 0048341 into trunk Oct 3, 2023
26 checks passed
@barryhughes barryhughes deleted the fix/40548 branch October 3, 2023 00:10
@github-actions github-actions bot added this to the 8.3.0 milestone Oct 3, 2023
@github-actions github-actions bot added the needs: analysis Indicates if the PR requires a PR testing scrub session. label Oct 3, 2023
@alopezari alopezari added needs: internal testing Indicates if the PR requires further testing conducted by Solaris status: analysis complete Indicates if a PR has been analysed by Solaris and removed needs: analysis Indicates if the PR requires a PR testing scrub session. labels Oct 3, 2023
@lanej0 lanej0 modified the milestones: 8.3.0, 8.2.0 Oct 3, 2023
github-actions bot pushed a commit that referenced this pull request Oct 3, 2023
lanej0 pushed a commit that referenced this pull request Oct 3, 2023
* Do not override pagination args if `woocommerce_hpos_pre_query` doesn't override query (#40551)

* Prep for cherry pick 40551

---------

Co-authored-by: Barry Hughes <3594411+barryhughes@users.noreply.github.com>
Co-authored-by: WooCommerce Bot <no-reply@woocommerce.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
focus: custom order tables / HPOS Issues related to High-Performance Order Storage (HPOS) née Custom Order Tables. needs: internal testing Indicates if the PR requires further testing conducted by Solaris plugin: woocommerce Issues related to the WooCommerce Core plugin. status: analysis complete Indicates if a PR has been analysed by Solaris
Projects
None yet
Development

Successfully merging this pull request may close these issues.

total and max_num_pages in the result of wc_get_orders() are null (instead of 0)
4 participants