Skip to content

Preserve originalValue when deferring imported template bindings - #1336

Open
manheychiu wants to merge 1 commit into
masterfrom
mchiu/preserve-original-on-deferred-import-bindings
Open

Preserve originalValue when deferring imported template bindings#1336
manheychiu wants to merge 1 commit into
masterfrom
mchiu/preserve-original-on-deferred-import-bindings

Conversation

@manheychiu

@manheychiu manheychiu commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Description

When an imported template ({% import %}) contains deferred nodes, ImportTag.handleDeferredNodesDuringImport defers the child's bindings onto the parent context. In the no-alias branch it overwrites every binding with a fresh, value-less DeferredValue.instance(), discarding any originalValue the binding already had.

That breaks the second render pass: DeferredValueUtils.getDeferredContextWithOriginalValues only restores a deferred key when its originalValue != null. Once a binding is stamped value-less, it can no longer be repopulated — even for variables that had a perfectly good resolved value.

Fix

In the no-alias branch, if a child binding is already a DeferredValue with a non-null originalValue, keep it via DeferredValue.instance(originalValue) instead of the value-less form. Bindings without a real original still fall back to DeferredValue.instance(). This also brings the flat/no-alias branch in line with the aliased branch just below, which already preserves a value.

In handleDeferredNodesDuringImport (flat/no-alias branch), keep a child
binding's originalValue when it is already a DeferredValue, instead of
overwriting every key with a value-less DeferredValue.instance(). This
lets downstream second-pass repopulation restore inherited vars such as
request (which otherwise get stamped with no originalValue and can no
longer be repopulated). Fixes DeferredValueException: request on email
test-send/preview renders that use load_translations inside a deferred
{% if %} within an imported template.
@manheychiu
manheychiu marked this pull request as ready for review September 3, 2026 16:52
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.

2 participants