Make WordPress Core

Opened 14 months ago

Closed 12 months ago

Last modified 11 months ago

#51288 closed defect (bug) (fixed)

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 has-dev-note
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 (13)

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

14 months 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.

14 months ago

#3 @leogermani
14 months 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 14 months ago by leogermani (previous) (diff)

#4 @SergeyBiryukov
13 months ago

  • Description modified (diff)

#5 @SergeyBiryukov
13 months ago

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

#6 @davidbaumwald
12 months ago

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

This ticket was mentioned in Slack in #core by hellofromtonya. View the logs.

12 months ago

#8 @hellofromTonya
12 months ago

  • Keywords needs-refresh added

Per scrub today, this ticket needs a refresh and update to the DB version.

#9 @leogermani
12 months ago

  • Keywords needs-refresh removed

Patch refreshed

#10 @SergeyBiryukov
12 months ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 49572:

Database: Clean up the post_category column removed from DB schema for new installations in WordPress 2.8.

Its presence may conflict with WP_Post::__get(), which should generally fill the non-existent post_category property, but is not triggered if the column exists in the database.

Follow-up to [10895].

Props leogermani, davidbaumwald, hellofromTonya.
Fixes #51288.

#11 @desrosj
11 months ago

  • Keywords needs-dev-note added

Let's mention this in the miscellaneous developer note.

Note: See TracTickets for help on using tickets.