Scope of "provided" context variables is wrong

Created on 26 November 2019, over 5 years ago
Updated 9 February 2025, about 2 months ago

Conditions and Actions may provide context variables by using the "provides" key in the plugin annotation. For example, the annotation of the "Add a variable" action looks like this:

 * @RulesAction(
 *   id = "rules_variable_add",
 *   label = @Translation("Add a variable"),
 *   category = @Translation("Data"),
 *   context = {
 *     "type" = @ContextDefinition("string",
 *       label = @Translation("Type"),
 *       description = @Translation("Specifies the type of the variable that should be added."),
 *       assignment_restriction = "input"
 *     ),
 *     "value" = @ContextDefinition("any",
 *       label = @Translation("Value"),
 *       description = @Translation("Optionally, specify the initial value of the variable."),
 *       required = FALSE
 *     ),
 *   },
 *   provides = {
 *     "variable_added" = @ContextDefinition("any",
 *       label = @Translation("Added variable")
 *     ),
 *   }
 * )

This "provides" key allows the action to add a variable, named "variable_added" into the context for the Rule.

The problem is that it appears "variable_added" is always available in the context, for every other condition or action, even those that are defined BEFORE the variable is added. This is not right - the added variable should only be in the context of conditions or actions that appear AFTER the variable is added.

We could use tests to demonstrate the problem, and to demonstrate the fix when we have one.

πŸ› Bug report
Status

Active

Version

4.0

Component

Rules Core

Created by

πŸ‡ΊπŸ‡ΈUnited States tr Cascadia

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024