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 | Owned by: | jeremyfelt |
---|---|---|---|
Milestone: | 4.2 | Priority: | normal |
Severity: | normal | Version: | 3.0 |
Component: | Taxonomy | Keywords: | has-patch |
Focuses: | multisite | Cc: |
Description (last modified by )
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)
Change History (13)
#2
@
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
@
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
@
10 years ago
- Keywords reporter-feedback removed
@valendesigns from a clean multisite install with global terms enabled.
- Create two sites 1 & 2
- Add two categories: A & B to site 1
- Add category: C to site 2
- Add category: A to site 2
#5
@
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
@
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
@
10 years ago
@boonebgorges That's great news! Thanks for taking over and finding a way to test this.
#8
@
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
@
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
@
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.
Patch to file the error