Using one variable for different things can be very dangerous. See the code:

  $entities = entity_load('entity_rule_setting', FALSE, $conditions);
  if ($load_rules) {
    foreach (array_keys($entities) as $entity_id) {
      $entities[$entity_id]->rules_config = rules_config_load($entities[$entity_id]->rules_config);
      // If rule didn't load unset this entity
      if (empty($entities[$entity_id]->rules_config)) {
        unset($entities[$entity_id]);
      }
    }
  }

It uses the same rules_config property to store either the string or the object. The problem arises when this entity is cached in entity_load(), so the first entity_load() call returns a string in this property, and the second entity_load() call returns the object loaded by rules_config_load(). This is the common case if you define both 'update rule' and 'validation rule' for the same entity bundle.

The proposed patch adds checking of value type of rules_config property.

Comments

tedbow’s picture

@maximpodorov , maybe we should store it in different property on the object altogether?

maximpodorov’s picture

Yes, it's better if it doesn't break the existing code. But storing entity rules configuration in entities was added recently, so it seems safe to modify this internal structures.

tedbow’s picture

Ok here is patch that adds a "loaded_rules_config" property

maximpodorov’s picture

Status: Needs review » Reviewed & tested by the community

Looks reasonable. And no more warnings with the last patch.

tedbow’s picture

Ok committed this to 7.x-1.dev

tedbow’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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