I am writing simpletests for the activity module. One thing that I want to do is set up relationships programmatically. To do this I am simply doing database inserts because of the arg(3) requirements in the api functions (but that's another story). The bug that I've found is that user_relationships_relationship_types_load() gets called several times in the page request. In particular, it statically caches the relationships as soon as it finds any:


function user_relationships_relationship_types_load() {
  static $relationship_types_list = array();

  if (!sizeof($relationship_types_list)) {

This check !sizeof() destroys the possibility of creating more than one relationship in a page request. This would, for example, prevent you from making install profiles that set up relationships. It also effectively prevents unit testing.

I see one option for fixing this, but there are certainly others. You could add a $clear flag to the user_relationships_relationship_types_load() function and call it whenever a new relationship gets created so that the static cache gets invalidated. This is a pattern that is used in Drupal core.

Comments

robertdouglass’s picture

PS I haven't checked whether the 5.2.x branch suffers the same problem.

sprsquish’s picture

Status: Active » Fixed

fixed on 5x-1.1 and 5x-2.x-dev

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.