hook_load can overwrite information: should be documented

fgm - October 9, 2005 - 11:06
Project:Documentation
Component:Developer Guide
Category:bug report
Priority:normal
Assigned:Unassigned
Status:closed
Description

The description for hook_load says that It is called to allow the module a chance to load extra information that it stores about a node. and that the returned object will be merged with the passed-in $node to result in an object containing both sets of properties.

This is not exactly what happens: node.module/node_load does not exactly return the node containing both sets of properties, but the passed-in properties, plus the extra properties added by the hook_load implementation, which can replace the passed-in properties if the returned object contains keys having the same name as the passed-in properties, which means they are not only "extra" properties.

This means existing properties loaded in the first part of node_load can be overwritten, or even removed by hook_load (using unset), which should be
- either documented if this is the desired behaviour for the code,
- or avoided by sanitizing the return value of hook_load through checking for duplicates with the passed-in values.

Page affected:
http://drupaldocs.org/api/head/function/node_load
http://drupaldocs.org/api/4.6/function/node_load

#1

fgm - October 9, 2005 - 11:12

Error in description: they can't be removed by using unset, but giving them a null value effectively erases the previous value without leaving any usable value.

#2

fgm - October 9, 2005 - 11:46

Here is a suggested patch with a more accurate wording.

AttachmentSize
node.php.patch 1.11 KB

#3

Gábor Hojtsy - October 9, 2005 - 11:46

This is intended. This is the feature used by excerpt module to inject the proper teaser for example AFAIR.

#4

Bèr Kessels - October 9, 2005 - 12:36
Status:active» needs review

@Goba: yes, intended, but undocumented. Documents say they are *inserted*, while in fact they are *inserted* OR *replaced*. This patch changes that documentation error, only.

A +1

#5

fgm - October 9, 2005 - 14:10

Previous version contained a typo.

AttachmentSize
node.php_0.patch 1.11 KB

#6

drewish - October 30, 2005 - 19:41

looks good +1

#7

Dries - November 5, 2005 - 07:33
Status:needs review» fixed

Committed to HEAD.

#8

Anonymous - November 19, 2005 - 07:40
Status:fixed» closed
 
 

Drupal is a registered trademark of Dries Buytaert.