Skip to content

Rewrite renamed Jinja references anywhere inside {{ }} and {% %} delimiters - #8455

Open
Theater-ahyeon wants to merge 1 commit into
Skyvern-AI:mainfrom
Theater-ahyeon:fix/jinja-reference-statement-rewrite
Open

Rewrite renamed Jinja references anywhere inside {{ }} and {% %} delimiters#8455
Theater-ahyeon wants to merge 1 commit into
Skyvern-AI:mainfrom
Theater-ahyeon:fix/jinja-reference-statement-rewrite

Conversation

@Theater-ahyeon

Copy link
Copy Markdown

Description

Fixes #7559.

replace_jinja_reference() only matched the renamed identifier directly after {{, so after a sanitization-driven rename (invalid identifier or collision _2 suffix) every reference that wasn't at the head of an expression kept pointing at the old name:

  • mid-expression uses like {{ current_index < max_attempts }} — the shape of a while-loop Condition;
  • statement blocks like {% if my-block_output.success %} and {% for item in old_key %}, which the old pattern never matched at all.

With lax templating nothing errors — conditions evaluate against undefined or wrong values, so loops mis-terminate and guards mis-fire.

The function now matches the old identifier as a whole word (lookbehind + lookahead on identifier characters, so {{ old_key_extended }} and {{ other_key }} stay untouched) inside every {{ ... }} / {% ... %} segment, and skips quoted string literals so filter defaults like default('old_key') keep their values. The sentinel-based atomic rewrite in _rewrite_error_code_mapping_refs_atomic keeps working unchanged: sentinels are plain-string-replaced in the second phase and contain no identifier characters.

How Has This Been Tested?

  • Extended the existing parametrized suite in tests/unit/test_workflow_parameter_validation.py with the issue's two reproductions (mid-expression {{ current_index < old_key }} and statement {% if old_key %}go{% endif %}), a {% for %} case, a quoted-literal case (default('old_key') keeps its value), and a statement partial-match case (other_old_key untouched).
  • uv run pytest tests/unit/test_workflow_parameter_validation.py → 70 passed (63 pre-existing cases all still green, including the sentinel-driven sanitizer tests).
  • Verified both reproductions from the issue now return the rewritten text, e.g. replace_jinja_reference("{{ current_index < max_attempts }}", "max_attempts", "max_attempts_2")"{{ current_index < max_attempts_2 }}".
  • ruff check clean on the touched files; ruff format applied.

…miters

replace_jinja_reference only matched an identifier directly after {{, so
renaming a parameter or block label left mid-expression references
(e.g. {{ current_index < max_attempts }}) and statement references
(e.g. {% if my-block_output.success %}) pointing at the old name. Match
the identifier as a whole word inside every Jinja segment instead, and
skip quoted string literals so filter defaults keep their values.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Renamed workflow identifiers are never rewritten inside {% %} statements or mid-expression Jinja references

1 participant