Skip to content

Step alias rendering raises SyntaxError when the step's if condition is false #6743

Description

@ausias-armesto

Step alias rendering raises SyntaxError when the step's if condition is false

Description

When a step defines both an alias block and an if condition, the alias
expressions are currently rendered before the if condition is
evaluated. If the step is meant to be skipped (its if evaluates to
false) and one of its alias expressions references the result of another
step that was itself skipped (and therefore has no result in the
context), rendering that alias produces broken output — e.g. a template
like:

keep.dictget({{ steps.get-incident.results.body }}, 'user_generated_name', 'Untitled incident')

renders steps.get-incident.results.body as an empty string, turning
the expression into the syntactically invalid keep.dictget(, 'user_generated_name', 'Untitled incident').

This raises a SyntaxError and aborts the workflow step entirely,
instead of the step being cleanly skipped as the if condition intends.

Steps to reproduce

  1. Define a step with an if condition that evaluates to false because
    it depends on the result of another step that was skipped.
  2. Give that step an alias whose expression references the same
    skipped step's result.
  3. Run the workflow.

Expected behavior

The step should be skipped without error — aliases should only be
evaluated once it's known the step will actually run.

Actual behavior

A SyntaxError is raised while rendering the alias expression, because
it's evaluated unconditionally before the if check.

Relevant code

keep/step/step.py, in Step._run_single — aliases are rendered and set
into the context near the top of the method, before the if condition
is checked further down.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions