Reaction rule throws exception when previewing node I have very simple reaction rule condition 'Node is Type' in Drupal 8 (8.5.3) Rules module (8.x-3.0-alpha3):

Data selector: @node.node_route_context:node


(Note: the mentioned issue occurs also for simple value node in the data selector.)

Content types: page


It works well when a node is viewed, but the rule causes crash with the error message The website encountered an unexpected error. Please try again later. when a node is previewed (button 'Preview' is clicked on the node form).

Note: To replicate the issue you should clear the cache on node form before hitting the 'Preview' button to ensure the node isn't served from the Drupal cache in which case Rules aren't fired.

The logged Error Message is:

Drupal\rules\Exception\EvaluationException: The context for node is NULL,
but the context node in rules_node_is_of_type requires a value.


Any hints on better Rules condition to catch the node type, or a patch for Rules?

Thank you!
I have found a workaround.

It seems that this is indeed a bug in the Rules module. The working solution is from here (although it was originally written for different situation, it fits this case as well): https://www.drupal.org/project/rules/issues/2929588#comment-12385257, and basically suggests to use a different condition:

Rule condition: 'Condition: Data comparison'
Data to compare (switched to data selection): node.type.target_id (Content type ID)
Operator (switched to Direct Input mode): ==
Value (switched to Direct Input mode): your_node_type


I hope this helps somebody.