Currently I had some odd behaviour when applying the event "After saving new content" for sending the user an Email. I wrote a little module (location_mobilemap.module) that creates a $node->location_mobilemap_key during hook_nodeapi() (=>http://drupalbin.com/5103).
With Rules I wanted to use this MobileKey to be sent in the message (i wrote a little token for that). But when inserting the new node, no mobile_key was in the message.

I recognized rules itself uses nodeapi:insert to fire the event. So there the weight of modules (in {system}) and alpha-order shall define what information is present in $node when calling the event. For any odd reason "rules" seemed to be called before "location_mobilemap", but L

After changing the weight of my module to -1, the whole thing worked. But because the event is called "After saving new content" this could not be the right fix. Therefore I think we have to find a way to ire the event after (!) nodeapi:insert, to ensure all variables have been saved. ( ---For having influence before the node is saved, there is the event "Content is going to be saved"---)

On way to ensure this was to set rule's weight to a big int +99 or so, but I cannot say what influnece this has to other events.

The same issue can be applied to "After updating existing content" I guess.

Comments

derhasi’s picture

Second paragraph gots destroyed... and no way to edit the issue, so rewriting it :(

Currently I had some odd behaviour when applying the event "After saving new content" for sending the user an Email. I wrote a little module (location_mobilemap.module) that creates a $node->location_mobilemap_key during hook_nodeapi() (=>http://drupalbin.com/5103).
With Rules I wanted to use this MobileKey to be sent in the message (i wrote a little token for that). But when inserting the new node, no mobile_key was in the message.

I recognized rules itself uses nodeapi:insert to fire the event. So there the weight of modules (in {system}) and alpha-order shall define what information is present in $node when calling the event. For any odd reason "rules" seemed to be called before "location_mobilemap", (but L is smaller than R).
To work around this problem I changed my modules weight to -1. It worked.

But as the event is called "After saving new content", it shall be called after the whole new content was saved, so it has to be fired after (!) nodeapi:insert
, to ensure all variables have been saved. ( ---For having influence before the node is saved, there is the event "Content is going to be saved"---)

On way to ensure this was to set rule's weight to a big int +99 or so, but I cannot say what influnece this has to other events.

The same issue can be applied to "After updating existing content" I guess.

rdmillner’s picture

I've run into this too. For the "After saving new content" event Rules is being called too early. No idea how to fix this though.

rdmillner’s picture

I managed to fix this with the Utility module (http://drupal.org/project/util). I activated the base module and "Module Weights," then set the Rules module weight at 999. This now works correctly.

fago’s picture

Status: Active » Closed (works as designed)

>But as the event is called "After saving new content", it shall be called after the whole new content was saved, so it has to be fired after (!) nodeapi:insert
It says, after saving new content. It got already saved, but it's not after modules have reacted on saving new content.. ;)

So rules relies on the hooks like any other module. For some cases one might need low weights, for others high - so I'd prefer to just keep the usual weight of 0. Anyway there is the util module to customize that.

mitchell’s picture

Title: Odd behaviour at node event "After saving new content" ->wrong weight? » Rules module weight of 0 leads to problems
Component: Provided module integration » Rules Engine
Status: Closed (works as designed) » Active
Issue tags: -nodeapi, -insert +rules 1.0

@fago: The current design is flawed.

Rules needs a way to either prevent or resolve its module weight conflicts. At the very least, it should include a link to the Util module in the warning messages, and even better would be to help the user fix them.

Perhaps Rules and/or Rules UI should include/depend on/reference this functionality for the specific purpose of fixing these errors. I believe you're talking about the Module Weights module in Utility.

fago’s picture

Status: Active » Closed (duplicate)

Agreed, we should increase the weight. See #445084: Adjust module weight from 0