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

Use delete query format suppored by wpdb::get_table_from_query() in Abstract_WC_Order_Data_Store_CPT::delete_items() #46692

Merged
merged 4 commits into from Apr 29, 2024

Conversation

prettyboymp
Copy link
Contributor

Changes proposed in this Pull Request:

Closes #46639.

This change updates the delete queries for order item meta in Abstract_WC_Order_Data_Store_CPT::delete_items() from the format of DELETE FROM {alias} USING {table} {alias} to a format of DELETE {alias} FROM {table} as {alias}. The former is not a format supported by wpdb::get_table_from_query() in WordPress core, so ::get_table_from_query() instead returns the alias as the table name. This breaks DB extensions like HyperDB that rely on the table name to determine what dataset to query from.

How to test the changes in this Pull Request:

This is difficult to isolate this specific code for testing. One option is to setup a site using HyperDB to route queries in a way that configured to only recognize tables starting with the default wp_ table prefix and attempt to remove order items from an order.

Alternatively, we can validate the queries specifically by duplicating them in a custom unit test that uses the WpdbExposedMethodsForTesting to expose the ::get_table_from_query() method. E.g:

public function test_delete_item_meta_queries() {
	global $wpdb;

	$test_wpdb = new WpdbExposedMethodsForTesting();
	$query = $wpdb->prepare( "DELETE itemmeta FROM {$wpdb->prefix}woocommerce_order_itemmeta as itemmeta INNER JOIN {$wpdb->prefix}woocommerce_order_items as items WHERE itemmeta.order_item_id = items.order_item_id AND items.order_id = %d AND items.order_item_type = %s", 1, 'foo' );
	$actual_table = $test_wpdb->get_table_from_query($query);
	$expected_table = "{$wpdb->prefix}woocommerce_order_itemmeta";
	$this->assertEquals($expected_table, $actual_table);

}

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 Update delete item meta query to format supported by wpdb::get_table_from_query()

Comment

…bstract_WC_Order_Data_Store_CPT::delete_items()
@github-actions github-actions bot added the plugin: woocommerce Issues related to the WooCommerce Core plugin. label Apr 17, 2024
@prettyboymp prettyboymp marked this pull request as ready for review April 17, 2024 17:17
@prettyboymp prettyboymp requested review from a team and vedanshujain and removed request for a team April 18, 2024 12:03
Copy link
Contributor

Hi @vedanshujain,

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

Copy link
Contributor

@vedanshujain vedanshujain left a comment

Choose a reason for hiding this comment

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

LGTM! Added some unit test around these flows, will merge after CI passes.

@vedanshujain vedanshujain enabled auto-merge (squash) April 22, 2024 07:52
@vedanshujain vedanshujain merged commit 1725ed2 into trunk Apr 29, 2024
22 of 23 checks passed
@vedanshujain vedanshujain deleted the fix/86639-delete-order-item-meta-query-hyperdb branch April 29, 2024 10:08
@github-actions github-actions bot added this to the 9.0.0 milestone Apr 29, 2024
@github-actions github-actions bot added the needs: analysis Indicates if the PR requires a PR testing scrub session. label Apr 29, 2024
@rodelgc rodelgc added needs: external testing Indicates if the PR requires further testing conducted by testers external to the development team. 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 May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs: external testing Indicates if the PR requires further testing conducted by testers external to the development team. 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.

Abstract_WC_Order_Data_Store_CPT::delete_items() query fails on HyperDB
3 participants