Make WordPress Core

Opened 4 years ago

Closed 3 years ago

Last modified 3 years ago

#51288 closed defect (bug) (fixed)

Drop deprecated database column upon upgrade

Reported by: leogermani's profile leogermani Owned by: sergeybiryukov's profile 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 ->

Change History (13)

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

4 years 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:

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

4 years ago

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

#4 @SergeyBiryukov
4 years ago

  • Description modified (diff)

#5 @SergeyBiryukov
4 years ago

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

#6 @davidbaumwald
4 years 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.

3 years ago

#8 @hellofromTonya
3 years ago

  • Keywords needs-refresh added

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

#9 @leogermani
3 years ago

  • Keywords needs-refresh removed

Patch refreshed

#10 @SergeyBiryukov
3 years 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
3 years ago

  • Keywords needs-dev-note added

Let's mention this in the miscellaneous developer note.

Note: See TracTickets for help on using tickets.