Sep 10 2009

WordPress 2.8 Schema Change Bug

Normally, WordPress is a good platform to manage simple websites and blogs. Despite the recent worm outbreak, if you keep it up to date, I still recommend it. However, when digging into the innards of the system, you occasionally come across a bug here or there that boggle the mind. Case in point, I recently stumbled across an attachment bug in the core files caused by a database schema change by the WordPress team. As far as I know, attachments have been a tried-and-true part of WordPress since version 2.5.

I discovered the bug after a client started using the WordPress iPhone app to manage their blog. No matter what I tried, uploaded photos weren't being attached to posts. It became an issue, because the theme I built required images to be attached to posts in order to display properly. Moreover, I started noticing many regular posts' images were randomly not attaching, even when posting through the regular admin.

After an hour of scanning code and searching the web, I found out WordPress had changed their post ID fields to bigint(20) UNSIGNED as of version 2.8. Well, this change broke image attachments in the XML-RPC script and in the admin when uploading media prior to saving a draft. Coincidentally, it also broke attachments via the QuickPress feature on the on new WordPress Dashboard.

To fix the XML-RPC page, I applied this patch. Since the field is UNSIGNED, the temporary ID of -1 the XML-RPC function uses is invalid. However, that didn't address the admin bug. That's when I found the MySQL workaround by 3 Dog Media:

ALTER TABLE wp_posts MODIFY post_parent BIGINT(20) NOT NULL DEFAULT 0; 

That query essentially removes the UNSIGNED attribute from the post_parent field in the wp_posts table, thus allowing the temporary negative IDs WordPress is still using, depsite the schema change. Note: The MySQL change fixes those all negative ID issues, so feel free to just apply that schema fix to your database.

Normally, I don't recommend core changes, because future updates will wipe them out. However, according to the bug ticket, the issue is deemed an edge case and won't be addressed until version 2.9. It's up to you to handle it until then.

0 comments

Sadly, no one has left a comment.