This is a really nasty bug that took me almost 1 day to narrow down!
To reproduce this bug:
1. Create a triggered rule "After existing content is updated"
2. Add an action "Show a configurable message on the site"
3. Set [node_unchanged:field_SOME-CCK-FIELD-raw] as message content
4. Edit an existing node with a SOME-CCK-FIELD field and change its value
5. Save
The displayed message is the updated value and not the unchanged one.

What is interesting there is that if you change the action's message content to:

[node_unchanged:field_SOME-CCK-FIELD-raw]
[node:field_SOME-CCK-FIELD-raw]

it works! The displayed message is the unchanged value followed by the updated one, as expected.

Why?
Because when both token are present, Token first replaces the node: one, then detects that the node_unchanged: one has the same token_id but in a different context, so it flushes cache before replacing it.
But when only one token is present, Token seems to considerer node_unchanged: as node:

I'm marking this as major as this bug is a really hidden nasty bug.

CommentFileSizeAuthor
#2 token_context_option-1167328-0.patch2.19 KBanrikun
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

anrikun’s picture

Version: 6.x-1.16 » 6.x-1.x-dev
Status: Active » Needs review
FileSize
2.19 KB

Here is a patch to fix this issue that introduces an extra caching context:

It takes advantage of the $option parameter available in token_replace and token_get_values, introducing a new "context" option.
When a context is provided, it is added to the cache id so that token values for this context are cached separately.

token_rules_input_evaluator_apply (token.rules.inc) has been modified to provide this context. This way, there is no more conflict between rules calls to token_replace and previously cached token.

token_cache has been removed from token_rules_input_evaluator_apply as it is not needed any more.

Dave Reid’s picture

Component: Code » Rules integration
Dave Reid’s picture

Priority: Major » Normal
anrikun’s picture

Status: Needs review » Closed (cannot reproduce)

Looks like this was fixed since then.

anrikun’s picture

Issue summary: View changes

Fixed some typos.