I'm using the EntityFieldQuery API to query a series of nodes for a specific domain. I then use node_load_multiple().

When looking at the results I noticed that all the nodes in the resulting array had the domain_source property of the node object set to the same value when in fact the nodes should have different domain_source values.

The problem seems to be something to do node_load_multiple() using the entiry_load() method instead of node_load(). I wrote my own function the iterates over the EntityFieldQuery results and returns the node objects using node_load(). The resulting array this time has the correct domain_source values.

Here is a example of the code using node_load_multiple():

$query = new EntityFieldQuery();		
$result = $query->entityCondition('entity_type', 'node')
	->entityCondition('bundle', 'page')
	->propertyCondition('status', 1, '=')
	->execute();	
	
$nodes = node_load_multiple(array_keys($result['node']));

kpr($nodes)
exit;

You'll need to install/enable the devel to use the kpr() function.

Here is my workaround that returns the correct domain_source values:

$query = new EntityFieldQuery();		
$result = $query->entityCondition('entity_type', 'node')
	->entityCondition('bundle', 'page')
	->propertyCondition('status', 1, '=')
	->execute();	
	
$nids = node_load_multiple(array_keys($result['node']));
$nodes = array();

foreach($nids as $nid) {
	$nodes[] = node_load($nid);
}

kpr($nodes)
exit;

I'm not sure if the bug is to do with the Domain Access module or a bug in Drupal core.

CommentFileSizeAuthor
#5 1219746-static-reset.patch1.3 KBagentrickard
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

agentrickard’s picture

Hm. Domain Source data isn't stored by FieldAPI, so I wonder what's going on here.

We've have problems with statics / loads in the past (you could search closed issues).

Does it matter if you do this:

$query = new EntityFieldQuery();
$result = $query->entityCondition('entity_type', 'node')
->entityCondition('bundle', 'page')
->propertyCondition('status', 1, '=')
->execute();

$nodes = node_load_multiple(array_keys($result['node']), array(), TRUE);

kpr($nodes)
exit;

Also note that in the query sample here, there is no need for EFQ, since 'bundle' is analogous to {node}.type.

agentrickard’s picture

Status: Active » Postponed (maintainer needs more info)
agentrickard’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)
agentrickard’s picture

Title: Node domain_source property is wrong when loading multiple nodes using node_load_multiple() » Cannot static cache _load() calls
Version: 7.x-2.12 » 7.x-3.x-dev
Priority: Normal » Major
Status: Closed (cannot reproduce) » Active

Found the problem. See #1307914: Document that the hook_entity_load() and hook_ENTITY_TYPE_load() functions should never have their own static caches.

Retitling issue as a general cleanup. This is now a release blocker.

agentrickard’s picture

Start at a patch. Needs more work and lots of test.