WordPress.org

Make WordPress Core

Opened 5 months ago

Closed 5 months ago

Last modified 5 months ago

#47313 closed defect (bug) (fixed)

Handle error in wp_insert_term if writing to the term_taxonomy table fails

Reported by: mbabker Owned by: SergeyBiryukov
Milestone: 5.3 Priority: normal
Severity: normal Version:
Component: Taxonomy Keywords: has-patch
Focuses: Cc:
PR Number:

Description

I ran into a bit of an edge case scenario where a custom WP-CLI command which was importing data from an incorrectly encoded CSV file would eventually trigger a call to wp_insert_term() inside another plugin and the insert query for the term_taxonomy table would not be executed as wpdb::strip_invalid_text() would rip out the invalid characters. Before isolating the file's encoding as the problem, the code that was calling wp_insert_term() was assuming a success state since an error wasn't being returned and its call to get_term() would end up not fetching the correct WP_Term object and start spitting out PHP "Trying to get property of non-object" notices as a result.

The upcoming patch adds a check inside wp_insert_term() to check for a false return from wpdb::insert() and will return a WP_Error if so.

Attachments (1)

wp_insert_term_catch_taxonomy_insert_error.diff (740 bytes) - added by mbabker 5 months ago.

Download all attachments as: .zip

Change History (5)

#1 @SergeyBiryukov
5 months ago

  • Component changed from General to Taxonomy
  • Keywords has-patch added
  • Milestone changed from Awaiting Review to 5.3

#2 @SergeyBiryukov
5 months ago

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

In 45362:

Taxonomy: In wp_insert_term(), handle an error if writing to the term_taxonomy table fails.

This complements the check for successful writing to the terms table, added in [7430].

Props mbabker.
Fixes #47313.

#3 follow-up: @johnbillion
5 months ago

The error message could probably be clarified a bit. How about Could not insert term taxonomy relationship into the database..

#4 in reply to: ↑ 3 @SergeyBiryukov
5 months ago

Replying to johnbillion:

The error message could probably be clarified a bit. How about Could not insert term taxonomy relationship into the database..

I've considered this, but thought it might be a bit more confusing, since the message is about the term_taxonomy table, not term_relationships.

"Term taxonomy" wording is used in quite a few DocBlocks, so the message seems fine as is to me.

Note: See TracTickets for help on using tickets.