Make WordPress Core

Opened 12 years ago

Closed 12 years ago

#21800 closed enhancement (fixed)

Include error reporting on failed DB INSERT in term_relationships

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

Description

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 12 years ago.
21800.patch (994 bytes) - added by SergeyBiryukov 12 years ago.

Download all attachments as: .zip

Change History (9)

#1 @SergeyBiryukov
12 years ago

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

Related: [6851] (for #5857).

#2 @scribu
12 years 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 12 years ago by scribu (previous) (diff)

#3 @scribu
12 years ago

  • Component changed from Taxonomy to Database

#4 follow-up: @jndetlefsen
12 years 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);

https://core.trac.wordpress.org/browser/trunk/wp-includes/taxonomy.php

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.

#5 in reply to: ↑ 4 @scribu
12 years 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.

#6 @ryan
12 years ago

  • Milestone changed from Awaiting Review to 3.5

#7 @ryan
12 years 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.