WordPress.org

Make WordPress Core

Opened 7 weeks ago

Last modified 10 days ago

#51288 reviewing defect (bug)

Drop deprecated database column upon upgrade

Reported by: leogermani Owned by: SergeyBiryukov
Milestone: 5.6 Priority: normal
Severity: normal Version:
Component: Database Keywords: has-patch
Focuses: Cc:

Description (last modified by SergeyBiryukov)

I just stumbled upon some issues with (very) old blogs that still have the post_category column in the posts table.

After this column was removed 11 years ago in [10895] / #9435, we never handled their removals on db upgrades.

This is an issue because we have a magic getter in WP_Post class that will fill the non existent post_category property. However, if the column exists in the database, the magic getter isn't triggered and we get 0 every time. So I think we can consider this a bug.

Link to the magic getter -> https://github.com/WordPress/wordpress-develop/blob/master/src/wp-includes/class-wp-post.php#L311

Change History (6)

This ticket was mentioned in PR #526 on WordPress/wordpress-develop by leogermani.


7 weeks ago

  • Keywords has-patch added; needs-patch removed

Adds an upgrade routine to drop the post_category column from the wp_posts table.

This column was dropped 11 years ago from the schema but never handled by an upgrade routine. Its presence may conflict with the magic getter in WP_Post class that populates the contents if you try to directly access the post_category object attribute.

Trac ticket: https://core.trac.wordpress.org/ticket/51288

This ticket was mentioned in Slack in #core-php by leogermani. View the logs.


7 weeks ago

#3 @leogermani
7 weeks ago

Test Instructions:

Alter your local database and add a post_category column to the wp_posts table.

Apply this patch.

Reload admin.

  • you should get a notice to Upgrade the DB
  • Click Upgrade
  • Check your database and verify the column was dropped.

Second test: Test if no errors are triggered if column not present.

Restore your current db version to force a new upgrade:

  • wp option set db_version 51287
  • Visit the dashboard again
  • You should see the Upgrade notice
  • Upgrade
  • Make sure there were no errors or warnings
Last edited 7 weeks ago by leogermani (previous) (diff)

#4 @SergeyBiryukov
5 weeks ago

  • Description modified (diff)

#5 @SergeyBiryukov
5 weeks ago

  • Milestone changed from Awaiting Review to 5.6
  • Owner set to SergeyBiryukov
  • Status changed from new to reviewing

#6 @davidbaumwald
10 days ago

Tested the most recent patch with the instructions in comment #3 and it works as expected.

Note: See TracTickets for help on using tickets.