Rewrite renamed Jinja references anywhere inside {{ }} and {% %} delimiters - #8455
Open
Theater-ahyeon wants to merge 1 commit into
Open
Rewrite renamed Jinja references anywhere inside {{ }} and {% %} delimiters#8455Theater-ahyeon wants to merge 1 commit into
Theater-ahyeon wants to merge 1 commit into
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #7559.
replace_jinja_reference()only matched the renamed identifier directly after{{, so after a sanitization-driven rename (invalid identifier or collision_2suffix) every reference that wasn't at the head of an expression kept pointing at the old name:{{ current_index < max_attempts }}— the shape of a while-loopCondition;{% 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 likedefault('old_key')keep their values. The sentinel-based atomic rewrite in_rewrite_error_code_mapping_refs_atomickeeps working unchanged: sentinels are plain-string-replaced in the second phase and contain no identifier characters.How Has This Been Tested?
tests/unit/test_workflow_parameter_validation.pywith 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_keyuntouched).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).replace_jinja_reference("{{ current_index < max_attempts }}", "max_attempts", "max_attempts_2")→"{{ current_index < max_attempts_2 }}".ruff checkclean on the touched files;ruff formatapplied.