Make builtin Jinja2 filters allowed on workers#943
Make builtin Jinja2 filters allowed on workers#943gmazoyer merged 3 commits intoinfrahub-developfrom
Conversation
WalkthroughEighteen Jinja2 builtin filters were updated to allow execution in WORKER context in addition to LOCAL context. The 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. @@ Coverage Diff @@
## infrahub-develop #943 +/- ##
====================================================
- Coverage 82.63% 81.45% -1.19%
====================================================
Files 133 133
Lines 13250 11253 -1997
Branches 2306 1690 -616
====================================================
- Hits 10949 9166 -1783
+ Misses 1652 1542 -110
+ Partials 649 545 -104
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 16 files with indirect coverage changes 🚀 New features to boost your workflow:
|
Deploying infrahub-sdk-python with
|
| Latest commit: |
81343a5
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://5555bc34.infrahub-sdk-python.pages.dev |
| Branch Preview URL: | https://gma-20260413-builtinfilters.infrahub-sdk-python.pages.dev |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
tests/unit/sdk/test_infrahub_filters.py (1)
102-111: Add a direct WORKER-positive regression test for a migrated builtin filter.These updated tests verify LOCAL-only behavior, but they no longer directly assert the core regression fix (a builtin like
safenow allowed inWORKER).Proposed test addition
class TestValidateContext: @@ def test_context_local_allows_local_only_filters(self) -> None: jinja = Jinja2Template(template="{{ data | fqdn_to_ip }}") jinja.validate(context=ExecutionContext.LOCAL) + + def test_context_worker_allows_worker_enabled_builtin_filter(self) -> None: + jinja = Jinja2Template(template="{{ data | safe }}") + jinja.validate(context=ExecutionContext.WORKER)🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/unit/sdk/test_infrahub_filters.py` around lines 102 - 111, Add a positive WORKER test that asserts a migrated builtin filter (e.g., "safe") is allowed in WORKER context: create a new test function (similar to test_context_worker_blocks_local_only_filters and test_context_local_allows_local_only_filters) that builds a Jinja2Template with template="{{ data | safe }}", calls jinja.validate(context=ExecutionContext.WORKER) and ensures it does not raise (i.e., no pytest.raises), verifying the migrated builtin is permitted in WORKER. Reference Jinja2Template.validate and ExecutionContext.WORKER when adding the test.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@docs/docs/python-sdk/reference/templating.mdx`:
- Around line 39-91: The templating reference table in
docs/python-sdk/reference/templating.mdx was edited directly but is generated;
revert this manual change and regenerate the SDK docs instead of editing the
file by running the docs generation task (uv run invoke docs-generate) to
produce updated files (including docs/python-sdk/reference/templating.mdx and
the related docs/python-sdk/reference/config.mdx and
docs/python-sdk/sdk_ref/**/*.mdx), then commit the regenerated output so the
table changes persist and don’t drift from source generation.
---
Nitpick comments:
In `@tests/unit/sdk/test_infrahub_filters.py`:
- Around line 102-111: Add a positive WORKER test that asserts a migrated
builtin filter (e.g., "safe") is allowed in WORKER context: create a new test
function (similar to test_context_worker_blocks_local_only_filters and
test_context_local_allows_local_only_filters) that builds a Jinja2Template with
template="{{ data | safe }}", calls
jinja.validate(context=ExecutionContext.WORKER) and ensures it does not raise
(i.e., no pytest.raises), verifying the migrated builtin is permitted in WORKER.
Reference Jinja2Template.validate and ExecutionContext.WORKER when adding the
test.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 03d7d327-c291-4b46-a4e6-cf695acb1947
📒 Files selected for processing (3)
docs/docs/python-sdk/reference/templating.mdxinfrahub_sdk/template/filters.pytests/unit/sdk/test_infrahub_filters.py
Why & What
This changes only marks Jinja2-builtin filters as allowed to be used in templates rendered by workers. Previously, the code rendering Jinja2 templates on worker was not validating which filters were allowed to be used.
When introducing allowed contexts for filters, and validating which ones can be used by the worker code, we can introduce what seems to be a regression from a user-perspective.
This should also be documented in the release notes Infrahub 1.9.
Summary by CodeRabbit
New Features
Documentation