inmanta / inmanta/std

Support references in std::template

Open
#680 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

compiler enhancement
Dominant language
Python
Stars
0
Forks
6
Avg merge
12h 25m
Merged PRs (30d)
5

Description

Context

The future module has a reference-aware jinja plugin (inmanta_plugins/future/std/__init__.py): when a reference ends up as a terminal value in a template, it is registered and replaced by a placeholder, and the plugin returns a JinjaReference (a Reference[str]) that finishes the render agent-side once the reference values are known. Everything that can be rendered at compile time is rendered at compile time.

It should move into std::template. Today it only works by monkeypatching core and std at render time (monkeypatch.py).

Discussion: Slack thread.

Blocked on inmanta/inmanta-core#10693, which covers the two core-side patches: allowing reference values through DynamicProxy for the duration of a render, and a supported interception point for a reference reaching a terminal position.

Scope of this ticket (std side)

  1. JinjaDynamicProxy.return_value — the std counterpart of the core proxy change: during a render, a reference reached through the jinja proxy must be passed through instead of rejected. future patches it to skip the reference guard; once core offers the supported mechanism, JinjaDynamicProxy should use it natively (scoped to the render, reverted on every exit path, including the UnsetException / MultiUnsetException control flow).

  2. Rendering the placeholder — core provides the hook that fires when a reference is stringified; std decides what to emit. In future that is {% endraw %}{{ references["<id>"] }}{% raw %}, with the reference stored in a render-local context. Note std::FactReference defines its own __str__, so it currently has to be registered by hand — whatever hook core lands on, std's own reference classes must route through it.

  3. JinjaReference — a Reference[str] holding the partially rendered template plus the map of registered references, resolving them agent-side and rendering the remainder. Needs a home in std, a stable serialization name, and handler-side tests.

  4. std::template behaviour — no references in the render ⇒ return the plain string exactly as today; references present ⇒ return a JinjaReference. Backwards compatibility of a plugin declared -> string returning a reference is part of the core discussion.

  5. preview-style introspectionfuture ships a preview plugin to inspect an unresolved value (plain string as-is, unresolved template for a JinjaReference, repr otherwise) without forcing resolution. Worth taking along, since error messages and model-side debugging otherwise show an opaque reference.

Definition of done

  • std::template supports references without patching core or std internals.
  • The template part of future::std can be dropped in favour of std.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with inmanta_plugins/future/std/init.py and monkeypatch.py to understand the existing reference-aware Jinja behavior, then review the core dependency in inmanta-core#10693. Trace JinjaDynamicProxy.return_value, JinjaReference, and the preview plugin, including handler-side tests. Done means std::template works without monkeypatching, preserves plain strings, and resolves reference-bearing templates agent-side.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.