Repository navigation
fix(eager): don't nest import aliases under a parent import that has finished - #1368
Merged
Merged
Conversation
…d importing
An aliased import inside a macro from another aliased import (e.g. a macro in
`{% import 'a.jinja' as outer %}` that does `{% import 'b.jinja' as inner %}`) built
the dotted alias `outer.inner` and walked `outer` by name from the calling scope to
nest the new alias map. Once the parent import has finished, that lookup can hit a
local variable instead of the alias map, which either threw "Encountered a problem
with import alias maps" (local is not a map) or put `inner` into the user's dict
(local is a map). Default execution mode has neither problem, so eager output
diverged from default output.
Only nest while the parent import is still in progress (its temporary import alias
is in scope), the same check EagerSetTagStrategy uses; otherwise bind the alias in
the current scope like a top-level import.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jasmith-hs
approved these changes
Nov 19, 2026
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
In eager execution, an aliased import inside a macro from another aliased import resolves the parent alias by name from the calling scope. If the caller has a local variable with the same name as that alias, the lookup finds the variable instead of the import's alias map. Default execution mode doesn't do this lookup, so eager output diverges from it:
InterpretException: Encountered a problem with import alias maps.{'name': 'local'}renders as{'name': 'local', 'printer': {}}.For example, with
{% import 'a.jinja' as outer %}{{ outer.render() }}, whererender()ina.jinjadoes{% set outer = ... %}and then{% import 'b.jinja' as printer %}.AliasedEagerImportingStrategynests a child import's alias map under its parent's (outer.printer) so nested imports are reconstructed correctly while the parent is being imported. It now only does that while the parent import is still in progress, which it detects with the parent's temporary import alias, the same checkEagerSetTagStrategyuses. Once the parent import has finished, the alias is bound in the current scope, like a top-level import and like default mode.Testing
EagerImportTagTest.itImportsInsideMacroWhenLocalVariableShadowsParentAlias: a string local shadowing the parent alias no longer throws.EagerImportTagTest.itDoesNotAddImportAliasToLocalDictShadowingParentAlias: a dict local shadowing the parent alias is left unchanged.This description was authored by Claude Code.
🤖 Generated with Claude Code