Preserve originalValue when deferring imported template bindings - #1336
Open
manheychiu wants to merge 1 commit into
Open
Preserve originalValue when deferring imported template bindings#1336manheychiu wants to merge 1 commit into
manheychiu wants to merge 1 commit into
Conversation
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
marked this pull request as ready for review
September 3, 2026 16:52
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
When an imported template (
{% import %}) contains deferred nodes,ImportTag.handleDeferredNodesDuringImportdefers the child's bindings onto the parent context. In the no-alias branch it overwrites every binding with a fresh, value-lessDeferredValue.instance(), discarding anyoriginalValuethe binding already had.That breaks the second render pass:
DeferredValueUtils.getDeferredContextWithOriginalValuesonly restores a deferred key when itsoriginalValue != 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
DeferredValuewith a non-nulloriginalValue, keep it viaDeferredValue.instance(originalValue)instead of the value-less form. Bindings without a real original still fall back toDeferredValue.instance(). This also brings the flat/no-alias branch in line with the aliased branch just below, which already preserves a value.