I have discovered incorrect behavior while setting up the FeedAPI module. It retrieves RSS items and adds nodes for every one of them. I am using it in conjunction with Automatic Nodetitles to automatically change their titles. This is where I found what I think is a bug in Token.
If I understand it correctly, the function token_get_values caches extracted values using the _token_get_id function to generate a key. The problem is that for known object types (node, comment, user) it unconditionally returns the object id (nid, cid, uid), even if it is still empty (node not yet saved). When there are multiple new nodes processed in a single request (as in the case of FeedAPI), this causes all of the replacements to be done using values of the first node.
Attached is a simple patch that makes things work correctly, but I don't guarantee that its the best way to fix this. I just copied crc32(serialize($object)) from the default case (unknown object type).
| Comment | File | Size | Author |
|---|---|---|---|
| token-fixed.patch | 789 bytes | TripleEmcoder |
Comments
Comment #1
TripleEmcoder commentedComment #2
dave reidYes, this is a good idea. Actually instead we can just return '0' for those new objects, and don't retrieve from cache if $id is equal to FALSE.
Fixed in CVS!
http://drupal.org/cvs?commit=337984