Skip to content

Detect and wrap missing Jinja expressions#350

Open
zhongkaifu wants to merge 2 commits intomainfrom
codex/update-code-to-handle-missing-jinja-expressions
Open

Detect and wrap missing Jinja expressions#350
zhongkaifu wants to merge 2 commits intomainfrom
codex/update-code-to-handle-missing-jinja-expressions

Conversation

@zhongkaifu
Copy link
Copy Markdown
Owner

Motivation

  • Some params contain Jinja-like variable expressions but are missing the surrounding {{ }} markers and should be auto-wrapped to become valid templates.
  • The change aims to detect those unwrapped variable-like strings and normalize them into proper Jinja template strings before validation/execution.

Description

  • Add POTENTIAL_JINJA_EXPR regex and helper looks_like_missing_jinja to identify variable-like text that appears to reference fields.
  • Add has_unwrapped_variable which uses the configured Jinja environment (get_jinja_env) to more strictly detect unwrapped expressions that can be parsed as Jinja expressions.
  • Modify _normalize_jinja_expr to call has_unwrapped_variable and automatically return a wrapped template like "{{ ... }}" when appropriate.
  • Add test_missing_jinja_expression_is_wrapped to tests/test_jinja_validation.py to cover the auto-wrapping behavior.

Testing

  • Ran python -m pytest tests/test_jinja_validation.py which executed the file's test suite.
  • All tests in that file passed (4 passed).

Codex Task

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant