Opened 9 months ago

Closed 9 months ago

#21800 closed enhancement (fixed)

Include error reporting on failed DB INSERT in term_relationships

Reported by: jndetlefsen Owned by: ryan
Priority: normal Milestone: 3.5
Component: Database Version: 2.5
Severity: normal Keywords: has-patch 2nd-opinion
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 9 months ago.
21800.patch (994 bytes) - added by SergeyBiryukov 9 months ago.

Download all attachments as: .zip

Change History (9)

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

Related: [6851] (for #5857).

  • 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 9 months ago by scribu (previous) (diff)
  • Component changed from Taxonomy to Database

comment:4 follow-up: ↓ 5   jndetlefsen9 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);

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.

comment:5 in reply to: ↑ 4   scribu9 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.

  • Milestone changed from Awaiting Review to 3.5
  • 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.