Make WordPress Core

#21800 closed enhancement (fixed)

Include error reporting on failed DB INSERT in term_relationships

Reported by: jndetlefsen Owned by: ryan
Milestone: 3.5 Priority: normal
Severity: normal Version: 2.5
Component: Database Keywords: has-patch 2nd-opinion
Focuses: Cc:


We have noticed that there is no error reporting when the database operation fail that inserts data into term_relationships. See attached file for suggested patch.

Attachments (2)

taxonomy.php.diff (1.2 KB) - added by jndetlefsen 23 months ago.
21800.patch (994 bytes) - added by SergeyBiryukov 23 months ago.

Download all attachments as: .zip

Change History (9)

jndetlefsen23 months ago

SergeyBiryukov23 months ago

comment:1 SergeyBiryukov23 months ago

  • Component changed from Database to Taxonomy
  • Keywords has-patch added
  • Version changed from trunk to 2.5

Related: [6851] (for #5857).

comment:2 scribu23 months ago

  • Keywords 2nd-opinion added

Actually, WP doesn't check anywhere if INSERT and UPDATE queries fail.

This has all sorts of interesting side-effects:

You can make the database read-only and WP will function normally, except for not saving any of your changes.

Then, if you add a persistent object cache on top, the changes will be saved in the cache but not in the database. And you'll scratch your head trying to figure out why your DB doesn't seem to be read-only anymore. :)

Last edited 23 months ago by scribu (previous) (diff)

comment:3 scribu23 months ago

  • Component changed from Taxonomy to Database

comment:4 follow-up: jndetlefsen23 months ago

There are already cases where a failed INSERTS causes a WP_Error, for example in line 2088 in the same file, taxonomy.php. Or am i missing something?

if ( false === $wpdb->insert( $wpdb->terms, compact( 'name', 'slug', 'term_group' ) ) )
    return new WP_Error('db_insert_error', __('Could not insert term into the database'), $wpdb->last_error);


Our situation is that we have to update blogposts on >1000 blogs on a multisite and in some cases the taxonomy relationships don't get written to the database. We want to wrap those updates into mysql transaction but as of now we have no way to know when inserts have failed so that we can rollback those transactions to avoid to have blogposts with no tags.

comment:5 in reply to: ↑ 4 scribu23 months ago

Replying to jndetlefsen:

There are already cases where a failed INSERTS causes a WP_Error, for example in line 2088 in the same file, taxonomy.php.

Yeah, then I guess we're just inconsistent. The idea is that we should fix this everywhere, not just when dealing with term relationships.

A good start would be adding checks for all the functions inside taxonomy.php. Then we can move on to post.php etc.

comment:6 ryan23 months ago

  • Milestone changed from Awaiting Review to 3.5

comment:7 ryan23 months ago

  • Owner set to ryan
  • Resolution set to fixed
  • Status changed from new to closed

In [21766]:

Return WP_Error if the db insert in wp_set_object_terms() fails. Props jndetlefsen. fixes #21800

Note: See TracTickets for help on using tickets.