Make WordPress Core

Opened 10 years ago

Closed 10 years ago

#31149 closed defect (bug) (fixed)

Error Object of class stdClass could not be converted to int in ms-functions.php on line 1788

Reported by: hauvong's profile hauvong Owned by: jeremyfelt's profile jeremyfelt
Milestone: 4.2 Priority: normal
Severity: normal Version: 3.0
Component: Taxonomy Keywords: has-patch
Focuses: multisite Cc:

Description (last modified by SergeyBiryukov)

Issue cause by $wpdb->get_row() return object to $local_id but was pass to global_terms to use as int. Fix by switching to $wpdb->get_var():

Change from:

$local_id = $wpdb->get_row( $wpdb->prepare( "SELECT term_id FROM $wpdb->terms WHERE term_id = %d", $global_id ) );

To correction:

$local_id = $wpdb->get_var( $wpdb->prepare( "SELECT term_id FROM $wpdb->terms WHERE term_id = %d", $global_id ) );

Attachments (2)

ms-functions.php.patch (654 bytes) - added by hauvong 10 years ago.
Patch to file the error
31149.diff (4.8 KB) - added by boonebgorges 10 years ago.

Download all attachments as: .zip

Change History (13)

@hauvong
10 years ago

Patch to file the error

#1 @SergeyBiryukov
10 years ago

  • Component changed from General to Taxonomy
  • Focuses multisite added

#2 @SergeyBiryukov
10 years ago

  • Description modified (diff)
  • Keywords has-patch needs-unit-tests added
  • Milestone changed from Awaiting Review to 4.2
  • Version changed from trunk to 3.0

Introduced in [13925].

#3 @valendesigns
10 years ago

  • Keywords reporter-feedback added

@hauvong What is the best way to duplicate the issue? I need to know how to break it so I can attempt to write the unit tests.

#4 @hauvong
10 years ago

  • Keywords reporter-feedback removed

@valendesigns from a clean multisite install with global terms enabled.

  1. Create two sites 1 & 2
  2. Add two categories: A & B to site 1
  3. Add category: C to site 2
  4. Add category: A to site 2

#5 @valendesigns
10 years ago

@hauvong Thanks for the directions. However, maybe I'm not enabling global terms properly or something, because I cannot reproduce the error. I've tried a couple different ways now with no luck. Any other help you can give to get setup? Cheers!

#6 @boonebgorges
10 years ago

The condition that leads to this error - ( $global_id != $local_id ) - is very difficult to trigger, as it only naturally occurs as the result of a race condition. After much gnashing of teeth, I've managed to fake a race condition in a unit test. Fix coming up.

#7 @valendesigns
10 years ago

@boonebgorges That's great news! Thanks for taking over and finding a way to test this.

@boonebgorges
10 years ago

#8 @boonebgorges
10 years ago

  • Keywords dev-feedback added; needs-unit-tests removed

31149.diff has a test that demonstrates the problem and the fix suggested by hauvong.

global_terms_enabled() stores the check in a static, which makes it impossible to toggle for the purposes of the unit tests. This was introduced in [14344] in what was, I assume, an attempt to optimize the function. @nacin do you have a problem if I roll this back and filter it every time the function is called? global_terms_enabled() is not called anywhere on the front end in core, and nowhere that I've found yet in the plugin repo, so I don't foresee any serious performance issues.

#9 @DrewAPicture
10 years ago

  • Owner set to jeremyfelt
  • Status changed from new to reviewing

@jeremyfelt: Can you please review that patch and give feedback, commit, or punt?

#10 @jeremyfelt
10 years ago

  • Keywords dev-feedback removed
  • Status changed from reviewing to accepted

The switch from retrieving an object ($wpdb->get_row()) to retrieving a string ($wpdb->get_var()) makes sense for 4.2. I'm hesitant to change the existing static behavior this late in a release, only because this bug went years without detection anyway. :)

I'm going to commit the first part and create a new ticket for the update to global_terms_enabled() with unit tests for 4.3-early.

#11 @jeremyfelt
10 years ago

  • Resolution set to fixed
  • Status changed from accepted to closed

In 32064:

Avoid an unexpected object error when syncing global terms

Pass the expected single value, rather than object, when recursively calling global_terms().

Props hauvong.

See #31914, Fixes #31149.

Note: See TracTickets for help on using tickets.