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

Fix: HPOS keeping disabled when the database tables were created via enabling the setting #40466

Merged
merged 2 commits into from
Sep 28, 2023

Conversation

Konamiman
Copy link
Contributor

@Konamiman Konamiman commented Sep 27, 2023

Submission Review Guidelines:

Changes proposed in this Pull Request:

When the HPOS tables don't exist and are created on the fly by setting the new tables as authoritative (via the dedicated UI tool, or by setting the new tables as authoritative in setting), the setting wasn't changing and the posts table were still authoritative after the tables creation was completed. With the fix, this will be the case only when the creation of the tables fails.

Additionally:

  • An error is logged if the tables can't be created, including the names of the affected tables.
  • A minor bug in DatabaseUtil::parse_dbdelta_output is fixed (the returned table names had a ( appended at the end).

How to test the changes in this Pull Request:

Happy path

  1. Make sure that the posts table is authoritative (via UI, in WooCommerce - Settings - Advanced - Features; or via command line, wp wc cot disable).
  2. Go to WooCommerce - Status - Tools and run the "Delete the custom order tables" tool. Verify that the tables have been deleted (e.g. wp_wc_orders).
  3. Change to the new tables as authoritative (via UI or via command line, wp wc cot enable).
  4. Verify that the new tables have been recreated and that thet are indeed authoritative by reloading the settings page in UI (without the fix, the posts table will still be authoritative).

Error path

To test the error case you'll need to do some temporary changes to the code (there's no need to delete the tables this time, just apply these changes while the new tables are authoritative):

  1. Remove/comment the first table of DataSyncrhonizer::create_database_tables (the one that invokes dbdelta).
  2. Add the following at the end of the string returned by OrdersTableDataStore::get_database_schema:
CREATE TABLE wp_wc_foobar (id int);
CREATE TABLE wp_wc_fizzbuzz (id int);

Now try to set the new tables as authoritative with wp wc cot enable. You'll get a " [Failed] Orders table could not be created" error, the posts table will be authoritative now, and if you check the logs you'll see the following entry: ERROR HPOS tables are missing in the database and couldn't be created. The missing tables are: wp_wc_foobar, wp_wc_fizzbuzz.

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

Fix: HPOS keeping disabled when the database tables were created via enabling the setting

Comment

After the fix HPOS will be disabled only if the creation of the
tables fail. Additionally, failure to create the tables will be logged.
@github-actions github-actions bot added the plugin: woocommerce Issues related to the WooCommerce Core plugin. label Sep 27, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Sep 27, 2023

Test Results Summary

Commit SHA: 98d923f

Test 🧪Passed ✅Failed 🚨Broken 🚧Skipped ⏭️Unknown ❔Total 📊Duration ⏱️
API Tests25900202611m 19s
E2E Tests212007021920m 28s

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.

@Konamiman Konamiman changed the title Fix: when the HPOS tables are created, HPOS was always disabled Fix: HPOS keeping disabled when the database tables were created via enabling the setting Sep 28, 2023
@Konamiman Konamiman marked this pull request as ready for review September 28, 2023 07:35
@github-actions
Copy link
Contributor

Hi @jorgeatorres,

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
Member

@jorgeatorres jorgeatorres left a comment

Choose a reason for hiding this comment

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

@Konamiman: This is missing the changelog file. Other than that, it looks good to me. Thank you for working on this!

@Konamiman
Copy link
Contributor Author

This is missing the changelog file.
I'm too used to it being generated automatically. It's added now.

Copy link
Member

@jorgeatorres jorgeatorres left a comment

Choose a reason for hiding this comment

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

LGTM. 🎉

@jorgeatorres jorgeatorres added the needs: analysis Indicates if the PR requires a PR testing scrub session. label Sep 28, 2023
@lanej0 lanej0 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 labels Sep 28, 2023
@lanej0 lanej0 merged commit 73c90bd into trunk Sep 28, 2023
32 of 33 checks passed
@lanej0 lanej0 deleted the fix/hpos-being-disabled-on-tables-creation branch September 28, 2023 21:59
@github-actions github-actions bot added this to the 8.3.0 milestone Sep 28, 2023
@nigeljamesstevenson nigeljamesstevenson removed the needs: analysis Indicates if the PR requires a PR testing scrub session. label Sep 29, 2023
@lanej0 lanej0 modified the milestones: 8.3.0, 8.2.0 Oct 3, 2023
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.

None yet

4 participants