[buddypress-trac] [BuddyPress Trac] #5570: `bp_get_member_profile_data` showing wrong values cached for other users

buddypress-trac noreply at wordpress.org
Tue Apr 22 00:44:22 UTC 2014


#5570: `bp_get_member_profile_data` showing wrong values cached for other users
-------------------------------+--------------------
 Reporter:  frederick.ding     |       Owner:
     Type:  defect (bug)       |      Status:  new
 Priority:  normal             |   Milestone:  2.0.1
Component:  XProfile           |     Version:  2.0
 Severity:  major              |  Resolution:
 Keywords:  reporter-feedback  |
-------------------------------+--------------------
Changes (by boonebgorges):

 * keywords:  dev-feedback => reporter-feedback


Comment:

 frederick.ding -

 Thanks very much for the analysis.

 I've been working on this, and I can't seem to reproduce. I've tried in
 the interface as well as a unit test. Please see the attached
 5570-test.patch. Does the logic in that test look correct to you? Three
 users; u1 and u3 have a value set for the field in question; then call
 `bp_get_member_profile_data()` inside of the `bp_has_members()` loop. If I
 understand your report correctly, the results should look like:

 {{{
 [u1] => 'foo'
 [u2] => 'foo' // incorrect
 [u3] => 'bar'
 }}}

 But what I'm seeing in my tests is the correct

 {{{
 [u1] => 'foo'
 [u2] => false
 [u3] => 'bar'
 }}}

 On top of this, I've ready through your analysis alongside the code and
 I'm afraid I don't completely follow the reasoning. I'm with you until
 this point:

 > When $fields is merged back into $groups on lines 279-299, the value of
 $groups[$index]->fields is assumed to be an empty array; in reality, the
 SQL query has already loaded data from other users. Thus, when a user-
 specific field is appended to $groups[$index]->fields, it ends up being
 appended to a collection of other users' information.

 You're correct that `$groups[ $index ]->fields` is assumed to be empty.
 But I don't see how `$fields` can contain another user's data. Yes, a SQL
 query has been loaded at this point in the codebase during this *page
 load*; but the information is stored in a variable whose scope is the
 function, and the function gets called different times for each user. Ie:

 u1 -> `bp_get_member_profile_data()` ->
 `BP_XProfile_ProfileData::get_data_for_user()` ->
 `BP_XProfile_Group::get()`

 u2 -> `bp_get_member_profile_data()` ->
 `BP_XProfile_ProfileData::get_data_for_user()` ->
 `BP_XProfile_Group::get()`

 u3 -> `bp_get_member_profile_data()` ->
 `BP_XProfile_ProfileData::get_data_for_user()` ->
 `BP_XProfile_Group::get()`

 The only way that the data could bleed through from one user to another is
 if there were a bug in the cache or if it were being stored in some
 polluted global - *not* by the local variable being polluted from user to
 user within the loop. I've looked, but I can't find any evidence that
 either of these things were happening. (See my comment above about not
 being able to reproduce the behavior you've described.)

 That said, it's possible that I'm misunderstanding here. Maybe I'm not
 grasping the crux of the issue? Maybe I've haven't tried the right things
 to reproduce the problem?

--
Ticket URL: <https://buddypress.trac.wordpress.org/ticket/5570#comment:3>
BuddyPress Trac <http://buddypress.org/>
BuddyPress Trac


More information about the buddypress-trac mailing list